This is a part of job interview question which got harder in its second part.
Given two 2-3 trees T1 and T2 such that for each tree h
in known (h for height) and m
, M
for each tree are known too (m for minimum and M for maximum), Plus that each node in T1
< every node in T2
.
I was asked to find an algorithm to join both of them into one tree in O(|h1-h2|+1)
This one was quite easy, and I have to point that this algorithm may result in a tree with h bigger than the previous two.
Now, I was given k
2-3 trees (T1,T2,T3...Tk) with the same exact conditions plus knowing that h_1<=h_2<=...<=h_k
and that no three trees share the same height to join them in O(h_k-h_1+k)
.
At first I thought about using the previou algorithm to join the first two together then to join the third to the result and so on but I felt that something is going wrong here since I didn't utilise the fact that "no three trees share the same height".
What I am missing here?