0

I was given this question on a test: "show by induction, that for a given AVL tree of height h, all levels of the tree until h/2 (round down) are complete binary trees". I wrote down the following answer and would like to know if my argument stands.

base: h= 0-> then level 0/2 is complete binary tree since theres just a root. h=1-> same argument since 1/2 round down is zero

step: assume correctness for all avl trees with level h and show for h+1. assume we have a AVL tree of height h+1. remove the root and receive two AVL trees of height h or one h and one h-1. divide into two cases: h is even, h is odd. h is odd: h/2=(h-1)/2 (round down) so we get that the same levels on the two sub trees are complete by induction, add back the root and we get that all level h+1/2 are complete. h is even: if the trees are of different height then h/2= (h-1)/2 + 1 (round down). so since the taller tree is a complete binary tree until h/2 it stands that he is complete binary tree until level h-1/2. add back the root and we get h+1/2 is complete binary tree.

id like to know how close this is to a correct answer.

Yair
  • 99
  • 8
  • That is a nice assignment. Did you have any question about it? – trincot Jan 03 '22 at 21:21
  • yes, i solved it on a test and wanted to know what the full answer was – Yair Jan 04 '22 at 22:10
  • Your question is not really a question. If your question is "What is the answer?", then we expect to see traces of your effort, and why you think it is not the correct answer, or what the problem with it is. Show your work, and describe the problem you bump into. – trincot Jan 04 '22 at 22:31
  • I divided my answer into two cases: one where h is even and one where h is odd. I assumed that the statement is correct for h and went on to show correctness for h+1. in both cases i removed the root and ended up with two sub AVL trees of height h or one of h one of h-1. the statement holds for both, and i showed that for even and odd h, that the heights (h-1)/2=h/2 and so even though they might not be the same height when you round down it is the same height. Im just not sure if thats the correct way of showing it, so am looking for verification – Yair Jan 05 '22 at 08:33
  • Can you edit your question, and add this information *in* the question? – trincot Jan 05 '22 at 08:43

1 Answers1

0

The proof you have presented is indeed correct if you add parentheses where they are missing, and a few other improvements. See what I updated in bold:

base: h= 0-> then level 0/2 is complete binary tree since there's just a root. h=1-> same argument since 1/2 round down is zero.

step: assume correctness for all avl trees with level h and show for h+1. assume we have a AVL tree of height h+1. remove the root and receive two AVL trees of height h or one h and one h-1. divide into two cases: h is even, h is odd. h is odd: h/2=(h-1)/2 (round down) so we get that the same levels on the two sub trees are complete by induction, add back the root and we get that all level (h+1)/2 are complete. h is even: if the trees are of different height then h/2= (h-1)/2 + 1 (round down). so since the taller tree is a complete binary tree until h/2 it stands that he is complete binary tree until level (h-1)/2, which is h/2 - 1 as h is even. add back the root and we get h/2 is complete binary tree.

trincot
  • 317,000
  • 35
  • 244
  • 286