SolHW5S08

# SolHW5S08 - HW5F07 CS336 1 Define recursively functions...

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

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

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

Unformatted text preview: HW5F07 CS336 1. Define recursively functions height, number of nodes, number of leaves and number of internal (interior) nodes for extended binary trees. Solution: For the height function h :: T → N , we have h. h ( d, ∅ , ∅ ) = 0 h. 1 h ( d,l,r ) = 1 + max ( h ( l ) ,h ( r )) For the number of nodes # N :: T → N , we have # N. 0 # N ( d, ∅ , ∅ ) = 1 # N. 1 # N ( d,l,r ) = 1 + # N ( l ) + # N ( r ) For the number of leaves # L :: T → N , we have # L. 0 # L ( d, ∅ , ∅ ) = 1 # L. 1 # L ( d,l,r ) = # L ( l ) + # L ( r ) For the number of internal nodes # I :: T → N , we have # I. 0 # I ( d, ∅ , ∅ ) = 0 # I. 1 # I ( d,l,r ) = 1 + # I ( l ) + # I ( r ) 2. Show that the minimum number of internal nodes for an extended binary tree of height h is h . Solution: For the base case, we have h = 0 and t = ( d, ∅ , ∅ ), and # I ( d, ∅ , ∅ ) < # I. > = 0 < h = 0 > = h For the inductive step, the I.H. is the following: for trees of height k ≤ h with the minimum number of internal nodes, we have # I = k . We need to show that for tree of height h + 1 with the minimum number of internal nodes, we have # I = h + 1. Let t = ( d,l,r ) be a binary tree of height h +1 with the minimum number of internal nodes. W.L.O.G. let l be of height h with the minimum number of internal nodes and then r must be ∅ . (Otherwise we can subtract nodes 1 from the subtree without changing the height of t and that would be a contradiction.) Then we have # I ( t ) < t = ( d,l,r ) > = # I ( d,l, ∅ ) < # I. 1 > = 1 + # I ( l ) + # I ( ∅ ) < I.H. , # I. > = 1 + h + 0 < arith > = h + 1 Hence by P.M.I., Q.E.D....
View Full Document

{[ snackBarMessage ]}

### Page1 / 7

SolHW5S08 - HW5F07 CS336 1 Define recursively functions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online