Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose we have a ( max ) heap that stores integers. (By contrast, in a \"min\"

ID: 3686283 • Letter: S

Question

Suppose we have a (max) heap that stores integers. (By contrast, in a "min" heap the key at any node is less than or equal to the key at its children, so the smallest valued key is at the top of the heap.) Then, given an integer k, we would like to print all the values in this heap that are greater than k. Implement the following method to do this.

H is the array storage for the max heap, and n is the number of entries in the heap.

Note: The challenge is to do this efficiently. Use the heap order to reduce the number of entries of the heap to be examined.

Explanation / Answer

Answer :

I think if its only integer k and not the kth integer then a single scan will do.

u have k as ur value .run a loop from 1 to n then simply check each value of heap with the given integer k. if its greater just print it. The code :

public void printGreater ( int[] H , int n , int k )

{

  for( I = 0 ; I < n ; I++)

if( a [ I ] > k )

System.out.println ( a [ I ] );

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote