{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes47

# notes47 - Note These notes cover the material on trees...

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

Note: These notes cover the material on trees, priority queues, and heaps discussed on Feb. 19, 21, and 23rd by lecturer Gustavo Rodriguez-Rivera. HTML and graphics by: Steven Maus ([email protected]) Trees, Priority Queues, and Heaps! Trees - It is a data structure that reprensents a hierarchy. - When trees are well constructed [balance] lookup can take O(log(n)) - A is the root node - B is the parent of D and E nodes - C is the sibling of B - D and E are the children of B - D, E, F, and G are external nodes or leaves - A, B, and C are internal nodes - the depth or level of E is 2 (distance of E to the root) - the height of the tree is 3 - the degree of B (# of children) is 2 Binary Trees - It is a tree with all internal nodes of degree equal to 2. Example of a binary tree

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

View Full Document
- A, B, C, and D are internal nodes and their degree is 2 Example of a tree that is not a binary tree - Not a binary tree because degree of B is 1 and B is an internal node (B needs to be degree 2). Properties of binary trees - # of external nodes = # internal nodes + 1 - # of external nodes <= 2 height - height >= log 2 ( # external nodes ) Traversal of a Tree Preorder Traversal visit parent before children preorder( Node v ) { mark v; //parent for each child ch of v call: preorder(ch); preorder(A); - visit: A, B, D, H, I, E, C, F, J, G, K
Postorder Traversal visit(mark) children before the parent postorder( Node v ) { for each child ch of v: postorder(v); mark v; } postorder(A) - visit: H, I, D, E, B, J, F, K, G, C, A

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

View Full Document
Inorder Traversal visit left child, then parent, then right child inorder( Node v ) {
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