Question

In disjoint union suppose we have to merge two trees whose heights are respectively h1 and h2. Using this technique, the height of the resulted merged tree will be max(h1, h2) if h1 not equal to h2, or h1+1 if h1 == h2. Using this technique after an arbitrary sequence of merge operations starting from initial situation, a tree containing 'k' nodes has a height at most (floor of logk). This is proved by induction as follows.

Base: when k=1 height is 0. 0<= (floor(log 1))

Induction step: consider k >1 and by hypothesis therorm is true for all m such that 1<=m<k. A tree containing k nodes can be obtained by merging two smaller subtrees. suppose these two smaller trees contain respectively 'a' and 'b' nodes where we may assume with out loss of generality a<=b. Now a>=1, therefore there is no way of obtaining a tree with zero nodes starting from the initial situation, and k=a+b. It follows that a<=k/2 and b<=k+1, since k>1, both k/2 < k, and (k-1) < k and hence a<k, and b<k.

My question on above is

  1. How we got "It follows that a<=k/2 and b<=k+1" statement above.

Thanks!

Was it helpful?

Solution

Let's assume a > k/2, then b > k/2, because b>=a. Then a + b > k/2 + k/2. Thus, a + b > k. But we have k = a + b! So the assumption that a > k/2 is leads to a contradiction, and is thus false. This 'proves' that a <= k/2.

In english: if we split k in two parts a and b, where b is bigger half, than a must be less than half of k.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top