2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington ...

12
2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis, and Thomas Kuehne, VUW COMP 103 Marcus Frean “Various topics”

Transcript of 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington ...

Page 1: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria

University of Wellington

Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis, and Thomas Kuehne, VUW

CO

MP 1

03

Marcus Frean

“Various topics”

Page 2: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

2

RECAP Linked lists Trees

TODAY Don’t want to rush into trees

Announcements No lecture this Thursday

Page 3: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

3

Generalised LinkedNode

Representing trees in Java

M

Linked List Nodes

F C

Page 4: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

4

Generalised LinkedNode

Representing trees in Java

Binary Tree Nodes

M

F C

T L

Page 5: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

5

Generalised LinkedNode

Representing trees in Java

General Tree Nodes

F…

…… C

……

M…

……

T…

…… L

……

some collection type(ordered or unordered)

Page 6: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

6

More Tree Examples Other Taxonomies

e.g. game genres Organisational Charts

CEO, managers, employees, slaves, … Filing systems

e.g., the folder structure of your hard drive Computer Graphics models

Octrees, for partitioning 3D space Decision processes …

hierarchical structuresnaturally represented with trees(rather than using trees as an

access technique)

Page 7: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

7

Planning

Tic Tac Toe search tree for

moves

XX XX X X …

O XO X XO

XO

XO

X

O…

often not represented explicitly;

only implicitly “created” by recursion

Page 8: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

8

More Tree Terminology A tree is a collection of items in a strict hierarchical

structure. Each item is in a node of the tree. The root is at the top. The leaves are at the bottom. Each node may have child nodes – except a leaf, which

has none. Each node has one parent - except the root, which has

none. An edge joins a node to its parent – may be labelled. A subtree is a node plus all its descendents. The depth of a node is its distance from the root. The height or depth of a tree is the depth of the lowest

leaf. Level = set/list of nodes at the same depth. Branch = sequence of nodes on a path from root to a

leaf.

Children may be ordered/unordered

Tree may or may not store explicit parent

references

Page 9: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

9

Terminology visualised

K

G

C I M Q

O

A E

node, root, leaf, child, parent, edge, subtree, depth, height, level, branch,siblings, ancestors, descendants, cousins, …

Page 10: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

10

remember that test?I see there are lots of scripts uncollected:

if you haven’t already, pick up your script from the office on the 3rd floor

Check our addition... Look at the solutions and make sure you understand

everything Our answer for Q3c was wrong – we’ll give everyone

who sat the test those marks.

Page 11: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

11

processing.org “processing” is a programming environment that you

might enjoy exploring...

write in java: processing takes care of most of the “icky stuff” (such as main...).

end result can be run in a web page

Page 12: 2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

12

python python is a programming language that you might

enjoy exploring...

“scripting” language – interpreted, not compiled not “strongly typed” (whereas Java is) fast to write avoid loops.... but numpy graphics via pylab library

FightClub...