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

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

asked in Algorithms by Loyal (3.9k points)   | 95 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 (721 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 May 2017
  1. akash.dinkar12

    3146 Points

  2. pawan kumarln

    1608 Points

  3. sh!va

    1580 Points

  4. Arjun

    1326 Points

  5. Devshree Dubey

    1230 Points

  6. Angkit

    1028 Points

  7. Debashish Deka

    1012 Points

  8. Bikram

    970 Points

  9. LeenSharma

    810 Points

  10. srestha

    662 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. pawan kumarln

    234 Points

  2. Ahwan

    118 Points

  3. jjayantamahata

    106 Points

  4. joshi_nitish

    106 Points

  5. Aditya GN

    63 Points


22,722 questions
29,048 answers
65,039 comments
27,510 users