7-Trees and Stack Permutations

7-Trees and Stack Permutations - Trees Vertices(or nodes...

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

View Full Document Right Arrow Icon
Trees Vertices (or nodes) , edges, adjacent vertices, paths, simple paths, cycles, simple cycles of undirected graphs - no self references, no multiple edges. Connected graphs, components Let G be a graph with n>1 vertices.. Then G is a free tree iff 1. G is connected and has no simple cycles. 2. G has no simple cycles and n-1 edges. 3. G is connected and has n-1 edges. 4. G has no simple cycles and adding an edge between two nonadjacent vertices forms exactly one simple cycle. 5. G is connected and if an edge is deleted G becomes disconnected. 6. There is exactly one path between any two vertices. An oriented tree is a free tree with a designated vertex called the root . (Also called a rooted tree.) An ordered tree is an oriented tree with zero or more ordered subtrees T 1 , T 2 , . . ., T n , which are also ordered trees. Summary: Free tree - no root, no order Oriented tree - Free tree, root Ordered tree - Free tree, root, order. For n=4 nodes: 0 0 0 0 0 0 0 0 0 0 0 | / | \ / \ | | / | \ / \ / \ | | / | \ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | | / \ | | | / \ 0 0 0 0 0 0 0 0 0 0 | | | 0 0 0 2 Free 4 Oriented 5 Ordered For n=5 nodes: 0 0 0 0 0 0 0 0 0 0 0 0 | / \ / | | \ / \ / \ / \ | | | | / | \ / | | \ 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 | / \ | | | / \ | / \ / | \ | | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | | | / \ 0 0 0 0 0 0 | | 0 0 3 Free 9 Oriented (14 Ordered not shown) Binary trees, complete binary trees, full binary trees.
Image of page 1

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

View Full Document Right Arrow Icon
In a full binary tree the #leaf nodes = # internal nodes +1 Proof: Suppose # of nodes is n. Each node except the root has one edge coming into it and each internal node has exactly two edges coming out of it. The number of nodes is the # leaf nodes + number of internal nodes and the number of edges coming into all nodes is the same as the number coming out of all nodes. So, # edges coming in=n-1 # edges coming out =2(#internal nodes) n=#internal nodes + # leaf nodes # edgs coming in= # edges coming out Thus, n-1=2(#internal nodes)=#internal nodes + #leaf nodes - 1 Or, # leaf nodes=#internal nodes + 1 The number of binary trees with n nodes Construction: 0 / \ 0 < i < n i n-i Let b i be the number of binary trees with i nodes. Then b 0 =1 and b n = b 0 x b n-1 + b 1 x b n-2 + . . . + b n-1 x b 0 for n>0. So b 1 = b 0 x b 0 =1 b 2 = b 0 x b 1 + b 1 x b 0 = 1 x 1 + 1 x 1 =2 b 3 = b 0 x b 2 + b 1 x b 1 + b 2 x b 0 = 1 x 2 + 1 x 1 + 2 x 1 = 5 b 4 = b 0 x b 3 + b 1 x b 2 + b 2 x b 1 + b 3 x b 0 = 1 x 5 + 1 x 2 + 2 x 1 + 5 x 1 = 14 b 5 = . . Ordered forest - collection of zero or more ordered trees with each tree itself being given a designated order - 1 st , 2 nd , etc 1-1 correspondence n node Ordered forests n node Binary trees Give the construction! Indicate the recursive version of the transformation from an ordered forest of n nodes to its corresponding n node binary tree.
Image of page 2
Image of page 3
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