lecture_28_s2005

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

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

View Full Document Right Arrow Icon
1.00 Lecture 28 Trees Reading for next time: None. Please look over the lecture notes before class.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
Tree traversal examples g b x d w z v root c Inorder: start at root
Background image of page 5

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c Inorder: b root
Background image of page 6
Tree traversal examples g b x d w z v c Inorder: b c root
Background image of page 7

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c Inorder: b c d root
Background image of page 8
Tree traversal examples g b x d w z v c Inorder: b c d g root
Background image of page 9

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c Inorder: b c d g v root
Background image of page 10
Tree traversal examples g b x d w z v c Inorder: b c d g v w x z root
Background image of page 11

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c root Postorder: start at root
Background image of page 12
Tree traversal examples g b x d w z v c Postorder: c root
Background image of page 13

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c Postorder: c d root
Background image of page 14
Tree traversal examples g b x d w z v c Postorder: c d b root
Background image of page 15

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c Postorder: c d b v root
Background image of page 16
Tree traversal examples g b x d w z v c Postorder: c d b v w root
Background image of page 17

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

View Full DocumentRight Arrow Icon
Tree traversal examples g b x d w z v c Postorder: c d b v w z x g root
Background image of page 18
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.
Background image of page 19

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

View Full DocumentRight Arrow Icon
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
Background image of page 20
Image of page 21
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 47

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 Right Arrow Icon
Ask a homework question - tutors are online