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 Jun 2017
  1. Bikram

    3704 Points

  2. Arnab Bhadra

    1502 Points

  3. Hemant Parihar

    1502 Points

  4. Niraj Singh 2

    1481 Points

  5. junaid ahmad

    1432 Points

  6. Debashish Deka

    1384 Points

  7. Rupendra Choudhary

    1220 Points

  8. rahul sharma 5

    1220 Points

  9. Arjun

    1158 Points

  10. srestha

    1006 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 26 - Jul 02
  1. Arjun

    198 Points

  2. akankshadewangan24

    152 Points

  3. Debashish Deka

    138 Points

  4. Hira Thakur

    130 Points

  5. Soumya29

    104 Points


23,399 questions
30,111 answers
67,489 comments
28,424 users