notes30

notes30 - Week 4 Notes - Wei-Chia Sun Jan. 28, 2008 Trees:...

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

View Full Document Right Arrow Icon
Week 4 Notes - Wei-Chia Sun Jan. 28, 2008 Trees: A is root node C is sibling of B D, E are children of B D, E, F, G, H are external nodes A, B, C are internal nodes
Background image of page 1

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

View Full DocumentRight Arrow Icon
The depth level of E is 2 The height of the tree is 3 The degree (number of children) of B is 2 Ordered Tree – It is a tree where the subtrees at each node are ordered. Binary Tree: it is a tree with internal nodes of degree equal to 2.
Background image of page 2
Properties of trees: External nodes = # internal nodes + 1 Nodes at level i ≤ 2 i External nodes ≤ 2 height Using log 2 property Since # external nodes ≤ 2 height Applying log 2 ( ) in each side log 2 (# external nodes ) ≤ log 2 ( 2 height ) log 2 (# external nodes ) ≤ height height = O(log n) ٭ n=external + internal nodes Traversal of Trees Preorder Traversal Visit parent before visiting children:
Background image of page 3

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

View Full DocumentRight Arrow Icon
struct TreeNode{ TreeNode left; TreeNode right; Object o; } void preorder(TreeNode t){ If(t==null){ return; } print(t.o); preorder(t.left); preorder(t.right); } Postorder Traversal Visit children before visiting parents:
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

notes30 - Week 4 Notes - Wei-Chia Sun Jan. 28, 2008 Trees:...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online