GATE CSE
First time here? Checkout the FAQ!
x
0 votes
96 views

It should be 5 according to me.Pleas explain if they are correct.

asked in Algorithms by Loyal (4k points)  
retagged by | 96 views
Delete root. Put 196 as root. Compare it with its two children 120 and 130. Swap 120 and 196. Compare with 140 and 150. Swap 196 and 140. Compare with 180 and 190. Swap 196 and 180. 6 comparisons. Anything wrong with this?
arre..I did a mistake in solving..First time I replaced 130, and then 170. So 5 were coming. Yes u r correct. Thanks  :)

1 Answer

+1 vote
ans is 5 only.
answered by Junior (811 points)  
But at last level here, It is doing two comparisons. We have to just check that the node has two childeren and then compare with them, orelse one child orelse it is a leaf. But these things are had to be done in nearly all tree algorithms, and these steps are not increasing any comparisons here.
acc 2 u is it correct r nt?
Delete root. Put 196 as root. Compare it with its two children 120 and 130. Swap 120 and 196. Compare with 140 and 150. Swap 196 and 140. Compare with 180 and 190. Swap 196 and 180. 6 comparisons.
yes..it is correct according to me.
srry i think u r thinking 5 as corrrect ans
i m explaining abt why 5 is nt correct  
just a conflict.:)
oh..Actually someone cleared it above.. thanks for ur effort :)


Top Users Aug 2017
  1. ABKUNDAN

    4660 Points

  2. Bikram

    4366 Points

  3. akash.dinkar12

    3258 Points

  4. rahul sharma 5

    3042 Points

  5. manu00x

    2682 Points

  6. makhdoom ghaya

    2410 Points

  7. just_bhavana

    2100 Points

  8. Tesla!

    1918 Points

  9. stblue

    1682 Points

  10. joshi_nitish

    1608 Points


24,928 questions
32,024 answers
74,385 comments
30,113 users