Tutorial 5

Stacks

Queues

Trees

Level

Depth of Node/Tree

Height of Node/Tree

Alt text

Subtree

Tree ADT methods

Method Description
getElement() Returns element stored at this position
size() Returns the numer of positions in the tree
isEmpty() Indicates if the tree is empty
iterator() Returns an iterators of all elements
positions() Returns iterable collection of all positions
root() Returns position of the tree's root
parent(p) Returns position of parent
children() Return's iterable collection of p's children

Tree traversal

Alt text

Binary Tree terminology

Binary tree performance:

var description
nn number of nodes
ee number of external nodes
ii number of internal nodes
hh height

Performance:

h=o(logn)h= o(\log n) (when at least two nodes)

Proper Binary tree properties

Alt text