{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture05 - Trees Trees Binary tree and Binary tree...

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

View Full Document Right Arrow Icon
1 Trees Trees Binary tree and Binary tree traversals Expression trees Infix, Postfix, Prefix notation Binary Search Trees Operations supported Complexity
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
2 (Directed) Tree 7 6 3 4 3 2 1 8 7 1 6 9 2 3 9 8 2 8 0 5 4 6
Image of page 2
3 Definition of Trees /\ is a tree. It is called an “empty tree”. If is a node and are non-empty trees where k 0, then is a tree. T 1 T 2 T k T 1 T 2 T k
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
4 Notation about Trees root, subtrees parent, child, sibling leaves, internal nodes edge path, length ancestor, descendant depth, height Root at depth 0, One node tree : height 0 7 6 3 4 3 2 1 8 8 2 8
Image of page 4
5 Tree criteria Always a single root A single path to every node Doesn’t matter how we draw it
Image of page 5

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

View Full Document Right Arrow Icon
6 Trees ? 4
Image of page 6
7 Game tree 1 2 7 2 1 3 8 6 X 1 2 7 2 1 X 8 6 3 1 2 7 2 1 3 8 X 6 Start state for the 8- puzzle; X marks the empty square. Can move the 3 tile into the empty square, or, can move the 6 tile into it. Goal of the game is to place all tiles in some special order.
Image of page 7

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

View Full Document Right Arrow Icon
8 Binary Trees Binary tree : every node has at most 2 children (left child and right child) N-ary tree : no node has more than N children. Advantages? Disadvantages? Equivalencies? 7 6 5 4 3 2 1 8
Image of page 8
9 Some Properties of Binary Trees Suppose a binary tree has n nodes, and height h. The total numbers of nodes: h+1 n 2 h+1 -1 The height of the tree: (from inequality above) log(n+1)-1 h (n-1)
Image of page 9

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

View Full Document Right Arrow Icon
10 Implementation of Binary Trees 7 6 5 4 3 2 1 8 x 2 1 7 8 3 4 6 5
Image of page 10
11 Binary Trees LL INFO RL node T L R (((a+b)*(c+(d-3))) LL: left link RL: Right Link * + + - d 3 a b c T
Image of page 11

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

View Full Document Right Arrow Icon
12 Implementation of N-ary Trees 7 6 4 3 4 8 2 8 5 x
Image of page 12
13 Implementation of Trees 7 6 4 3 4 8 2 8 4 7 8 3 6 4 2 8 x Right link to siblings; left link to successors
Image of page 13

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

View Full Document Right Arrow Icon
14 Some applications Expressions ( (7+3*12+18) * (4/3) ) HTML or XML Word documents 3
Image of page 14
15 Traversing a tree Traversing a tree is to visit every node in the tree
Image of page 15

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

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