notes30

# notes30 - Week 4 Notes Wei-Chia Sun Jan 28 2008 Trees A is...

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

Week 4 Notes - Wei-Chia Sun Jan. 28, 2008 Trees: A is root node B is parent of D& E 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

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

View Full Document
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.
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:

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

View Full Document
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:
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern