100 likes | 191 Views
CISC220 Fall 2009 James Atlas. Lecture 12: Trees. Objectives for Today. Understand Trees/Terminology Use basic traversals on trees Reading - K+W Chap 8. Brainstorm. Come up with several ways to use our LinkedList to implement a Priority Queue
E N D
CISC220Fall 2009James Atlas Lecture 12: Trees
Objectives for Today • Understand Trees/Terminology • Use basic traversals on trees • Reading - K+W Chap 8
Brainstorm • Come up with several ways to use our LinkedList to implement a Priority Queue • Record the order of operations for each ADT function • front() • dequeue() • queue(x, int)
Trees • Nonlinear data structure
Tree Terminology • root, leaf • parent, child, sibling • subtree • external, internal node • ancestor, descendant • depth, height
Binary Trees • Each node has 0, 1, or 2 children
Tree Traversal • process of visiting each node • 4 different standard traversals: • preorder • inorder • postorder • level-order (also called breadth-first) • Interactive example: • http://nova.umuc.edu/~jarc/idsv/lesson1.html
Traversal Exercise Find the: • preorder • inorder • postorder • level-order
Exercise Answers • Preorder traversal sequence: F, B, A, D, C, E, G, I, H (root, left, right) • Inorder traversal sequence: A, B, C, D, E, F, G, H, I (left, root, right) • Postorder traversal sequence: A, C, E, D, B, H, I, G, F (left, right, root) • Level-order traversal sequence: F, B, G, A, D, I, C, E, H