in DS recategorized by
592 views
0 votes
0 votes
Consider the following array of elements

<96,42,50,17,15,5,7,11,39,23,6,9,19,100,12>

The minimum number of interchanges using buildheap needed to convert it into a max heap is
in DS recategorized by
592 views

2 Comments

  1. $1$ swap for $11\rightarrow39$
  2. $1$ swap for $15\rightarrow 23$
  3. $1$ swap for $5\rightarrow9$
  4. $1$ swap for $9\rightarrow19$
  5. $3$ swap for $7\rightarrow100;50\rightarrow100;96\rightarrow100$

Total swap required =$1+1+1+1+3=7$

1
1

@prajjwal_191 I did not understand how they randomly just swapped the elements in the end

@Hira Thakur your answer is more convincing if we consider the direction from left to right. thankyou

0
0

1 Answer

1 vote
1 vote

 

 

 

 

I hope you got it thankyou.

1 flag:
✌ Edit necessary (Bhavesh21)

4 Comments

@Hira Thakur  yupp mistakenly I wrote 17 as 7. Thank you for figuring it out.

1
1
so is 7 correct or 6 is correct answer?
0
0
6
0
0