{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
- 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
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
Inorder Traversal visit left child, then parent, then right child inorder( Node v ) {
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern