The difference between binary trees and full binary

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: f. 27 Example 2: Full Binary Trees The set of full binary trees can be defined as follows: Basis: There is a full binary tree consisting of a single vertex r Induction: If T1 and T2 are disjoint full binary trees and r in A is a node, then <T1, r, T2 > is a full binary tree with root r and left subtree T1 and right subtree T2. The difference between binary trees and full binary trees is in the basis step. A binary tree is full if and only if each node is either a leaf or has precisely two children. 28 Small Full Binary Trees Level 0: Level 1: not full! Level 2: 29 Height of a Full Binary Tree Let T be a full binary tree over an alphabet A. We define the height h(T) of a full binary tree as follows: Basis: For r in A, we define h(r) = 0; that is, the height of a full binary tree with just a single node is 0. Induction: If L and R are full binary trees and r in A, then the tree <L,r,R> has height h( <L,r,R> ) = 1 + max( h(L), h(R) ). 30 Number of Nodes of a Full Binary Tree Let n(T) denote the number of nodes of a full binary tree over an alphabet A. Then Basis: For r in A, we have n(r)=1. Induction: If L and R are full binary trees and r in A, then the number of nodes of <L,r,R> is given by n(<L,r,R>) = 1+n(L)+n(R). 31 Example of Structural Induction Theorem: Let T be a full binary tree over an alphabet A. Then we have n(T) <= 2h(T)+1-1. Proof: By structural induction. Basis step: For r in A, we have n(r)=1 and h(r)=0, therefore, we have n(r) = 1 <= 2(0+1)-1 = 2h(r)+1-1, as claimed. Inductive step: Suppose that L and R are full binary trees that satisfy n(L) <= 2h(L)+1-1 and n(R) <= 2h(R)+1-1. Then the tree T=<L,r,R> satisfies: n(T) = 1 + n(L) + n(R) <= 1 + 2h(L)+1-1 + 2h(R)+1-1 <= 2 max(2h(L)+1, 2h(R)+1)-1, since a+b <= 2max(a,b) <= 2.2max(h(L),h(R))+1 -1=2.2h(T)-1 = 2h(T)+1-1 32...
View Full Document

This note was uploaded on 03/24/2014 for the course CSCE 222 taught by Professor Math during the Fall '11 term at Texas A&M.

Ask a homework question - tutors are online