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

Post on 31-Dec-2015

216 views 1 download

Tags:

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

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”

2

RECAP Linked lists Trees

TODAY Don’t want to rush into trees

Announcements No lecture this Thursday

3

Generalised LinkedNode

Representing trees in Java

M

Linked List Nodes

F C

4

Generalised LinkedNode

Representing trees in Java

Binary Tree Nodes

M

F C

T L

5

Generalised LinkedNode

Representing trees in Java

General Tree Nodes

F…

…… C

……

M…

……

T…

…… L

……

some collection type(ordered or unordered)

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)

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

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

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, …

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.

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

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...