100 likes | 117 Views
Learn about trees and their terminology, and explore basic traversal techniques on trees. Discover various ways to implement a priority queue using a linked list. Record the order of operations for each ADT function.
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