# Category Archives: Heap

Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters, lengths of the assigned codes are based… Read More
Given N machines. Each machine contains some numbers in sorted form. But the amount of numbers, each machine has is not fixed. Output the numbers… Read More
Given an array of N elements, where each element is at most K away from its target position, devise an algorithm that sorts in O(N… Read More
Given that integers are read from a data stream. Find median of elements read so for in an efficient way. For simplicity assume, there are… Read More
Consider the following algorithm for building a Heap of an input array A.  BUILD-HEAP(A)      heapsize := size(A);      for i := floor(heapsize/2)… Read More
Given an array and an integer K, find the maximum for each and every contiguous subarray of size K. Examples :  Input: arr[] = {1,… Read More
Given a team of N players. How many minimum games are required to find the second-best player?   We can use adversary arguments based on… Read More
Heap Data Structure is generally taught with Heapsort. Heapsort algorithm has limited uses because Quicksort is better in practice. Nevertheless, the Heap data structure itself… Read More
Write an efficient program for printing K largest elements in an array. Elements in an array can be in any order Examples: Input:  [1, 23,… Read More