Category Archives: Heap

Print all nodes less than a value x in a Min Heap.September 19, 2017

Given a binary min heap and a value x, print all the binary heap nodes having value less than the given value x. Examples :… Read More »

Adding elements of an array until every element becomes greater than or equal to kAugust 24, 2017

We are given a list of N unsorted elements, we need to find minimum number of steps in which the elements of the list can… Read More »

std::make_heap() in C++ STLAugust 15, 2017

make_heap() is used to transform a sequence into a heap. A heap is a data structure which points to highest( or lowest) element and making… Read More »

Leftist Tree / Leftist HeapAugust 2, 2017

A leftist tree or leftist heap is a priority queue implemented with a variant of a binary heap. Every node has an s-value (or rank… Read More »

Median of Stream of Running Integers using STLJuly 14, 2017

Given that integers are being read from a data stream. Find median of all the elements read so far starting from the first integer till… Read More »

Merge k sorted linked lists | Set 2 (Using Min Heap)July 6, 2017

Given k sorted linked lists each of size n, merge them and print the sorted output. Examples: Input: k = 3, n = 4 list1… Read More »

Largest triplet product in a streamJune 27, 2017

Given a stream of integers represented as arr[]. For each index i from 0 to n-1, print the multiplication of largest, second largest, third largest… Read More »

Find k numbers with most occurrences in the given array

Given an array of n numbers and a positive integer k. The problem is to find k numbers with most occurrences, i.e., the top k… Read More »

Convert BST to Min HeapJune 17, 2017

Given a binary search tree which is also a complete binary tree. The problem is to convert the given BST into a Min Heap with… Read More »

Merge two binary Max HeapsJune 9, 2017

Given two binary max heaps as arrays, merge the given heaps. Examples: Input : a = {10, 5, 6, 2}, b = {12, 7, 9}… Read More »

How to implement stack using priority queue or heap?May 25, 2017

How to Implement stack using a priority queue(using min heap)?. Asked In: Microsoft, Adobe. Recommended: Please try your approach on {IDE} first, before moving on… Read More »

Applications of Priority QueueMay 14, 2017

A Priority Queue is different from a normal queue, because instead of being a “first-in-first-out”, values come out in order by priority. It is an… Read More »

Given level order traversal of a Binary Tree, check if the Tree is a Min-HeapMay 8, 2017

Given the level order traversal of a Complete Binary Tree, determine whether the Binary Tree is a valid Min-Heap Examples: Input : level = [10,… Read More »

Rearrange characters in a string such that no two adjacent are sameMarch 13, 2017

Given a string with repeated characters, task is rearrange characters in a string so that no two adjacent characters are same. Note : It may… Read More »

Implementation of Binomial HeapJanuary 22, 2017

In previous article, we have discussed about the concepts related to Binomial heap. Examples Binomial Heap: 12————10——————–20 / \ / | \ 15 50 70… Read More »