This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 141/17•Trees and tree terminology•Binary trees•Tree traversals •Implementations of treesCSE 12Binary Tree Properties142/17Binary Trees•A binary treeis a tree with an arity of 0, 1 or 2 – a node may have 0, 1, or 2 children (a) A full binary tree of height 3.(b) Complete binary trees of height 3 and 4.A full binary treeof height h is one in which all nodes from level 1 to level h– 1 have two children A complete binary treeof height his one in which all nodes from level 1 to h– 2 have two children and all the children of nodes at level h– 1 are contiguous and to the left of the tree 143/17Binary Tree properties•Consider a “full” binary tree (every level that has any nodes at all has as many nodes as possible):•How many nodes at level 1? ____•How many nodes at level 2? ____•How many nodes at level 3? ____ •Generalizing, how many nodes at level L? ____•And so, how many nodes in a full binary tree of height h? __________•And so, what is the height of a full binary tree with n nodes?________144/17Binary Tree properties•Generalizing, how many nodes at level L?•And so, how many nodes in a full binary tree of height h?•And so... what is the height of a full binary tree of size n?2L−1n=∑L=1h2L−1=2h−1( )( )n=h+n=hn=hlog1log122Θ−145/17Binary Tree propertiesProperty 10.1 A full binary tree of height hhas 2h– 1 nodesProperty 10.2 The height of a full binary tree with nnodes is. (This is also the length of the longest path in a full binary tree.)Property 10.3 The height of a binary tree with nnodes is at least and at most n (this “worst case” occurs when no node has more than 1 child)....
View
Full Document
 Fall '07
 Aben
 Tree traversal

Click to edit the document details