lecture_28_s2005

# lecture_28_s2005 - 1.00 Lecture 28 Trees Reading for next...

This preview shows pages 1–21. Sign up to view the full content.

1.00 Lecture 28 Trees Reading for next time: None. Please look over the lecture notes before class.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree definitions a d b g f i h c e Level (distance from root) 0 1 2 ... Root : a Degree (of node): number of subtrees b:3, c:0, d:2 Leaf : node of degree 0: e, c Branch : node of degree >0 Depth : max level in tree Children : of a are b, c, d Parent : of g is b Siblings : children of same parent: b, c, d Degree of tree : max degree of its nodes(3) Ancestors : nodes on path to root: g’s ancestors are b and a
Binary tree definitions 1 3 2 5 4 7 6 Level 0 1 2 ... Max nodes on level i= 2 i Max nodes in tree of depth k= 2 k+1 -1 (full tree of depth k) Binary tree in a 1-D array: Parent[i]= i/2 LeftChild[i]= 2i RightChild[i]= 2i+1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree Traversal Listing all the elements of a tree is more subtle than listing all the elements of a linked list, and there are a number of ways we can do it. We call a list of a tree's nodes a traversal if it lists each tree node exactly once. The three most commonly used traversal orders are recursively described as: Inorder: traverse left subtree, visit current node, traverse right subtree Postorder: traverse left subtree, traverse right subtree, visit current node Preorder: visit current node, traverse left subtree, traverse right subtree
Tree traversal examples g b x d w z v root c Inorder: start at root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c Inorder: b root
Tree traversal examples g b x d w z v c Inorder: b c root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c Inorder: b c d root
Tree traversal examples g b x d w z v c Inorder: b c d g root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c Inorder: b c d g v root
Tree traversal examples g b x d w z v c Inorder: b c d g v w x z root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c root Postorder: start at root
Tree traversal examples g b x d w z v c Postorder: c root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c Postorder: c d root
Tree traversal examples g b x d w z v c Postorder: c d b root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c Postorder: c d b v root
Tree traversal examples g b x d w z v c Postorder: c d b v w root

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree traversal examples g b x d w z v c Postorder: c d b v w z x g root
Tree Traversal Exercise Download: TreeTraversalApp TreeTraversalView VisualTreeNode Screen Run TreeTraversalApp Use the buttons on the bottom to explore tree definitions Use the buttons on the top to explore the three typical tree traversals: inorder, preorder, and postorder.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Binary Search Trees There are many ways to build binary trees with varying properties: In a heap or priority queue , the largest element is on top. In the rest of the heap, each element is larger than its
This is the end of the preview. Sign up to access the rest of the document.

## lecture_28_s2005 - 1.00 Lecture 28 Trees Reading for next...

This preview shows document pages 1 - 21. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online