Check if an array represents a min-heap or not
Given an integer array, check if it represents min-heap or not. For example, the first array represents a min-heap, but the second array doesn’t violate the heap property.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven an integer array, check if it represents min-heap or not. For example, the first array represents a min-heap, but the second array doesn’t violate the heap property.
Heapsort is an in-place, comparison-based sorting algorithm and can be thought of as an improved selection sort as it divides the input into a sorted and an unsorted region.
In previous post, we have introduced the heap data structure and covered heapify-up
, push
, heapify-down
and pop
operations. This article covers C++ implementation of Priority Queue Data Structure (Max Heap and Min heap).
A priority queue is an ADT (Abstract Data Type) for maintaining a set S
of elements, with each element having a “priority” associated with it. In a priority queue, an element with high priority is served before an element with low priority or vice versa.
Given a source vertex s
from a set of vertices V
in a weighted graph where all its edge weights w(u, v)
are non-negative, find the shortest path weights d(s, v)
from source s
for all vertices v
present in the graph.