Guest User

Untitled

a guest
May 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. -- haskell
  2.  
  3. data Tree = Leaf | Node Tree Tree
  4.  
  5. N :: Tree -> Int
  6. N (Leaf) = 0
  7. N (Node T1 T2) = (N T1) + (N T2) + 1
  8.  
  9. H :: Tree -> Int
  10. H (Leaf) = 0
  11. H (Node T1 T2) = 1 + (max (H T1) (H T2))
  12.  
  13. -- Prove by induction that (N t) < 2^(H t)
  14.  
  15. P(t) := (N t) < 2^(H t)
  16.  
  17. We'll prove that forall t: Tree . P(t) by induction on t
  18.  
  19. Base Case (P(Leaf))
  20.  
  21. N Leaf = 0
  22. < 1
  23. = 2^0
  24. = 2^(H Leaf)
  25.  
  26. Step Case: Assume forall l,r:Tree . P(l),P(r). We show that P (Node l r) holds
  27.  
  28. N (Node l r) = N l + N r + 1
  29. < 2^(H l) + 2^(H r) + 1 (I.H)
  30. < 2^(1 + (max (H l) (H r)))
  31. = 2^(H (Node l r))
Add Comment
Please, Sign In to add comment