## C++ Standard Template Library (STL) – [Heap]

The Heap data structure is an array that can be viewed as a complete Binary Tree. Each node in the tree corresponds to an element of the array A[]. We already discussed Heap data structure in this – post. However in this post we would learn about, how to build min/max Heaps […]

## Heap Sort in C++

The Heapsort algorithm uses Heap data structure to sort an array in O(nlogn) time complexity. It starts by calling Build-Max-Heap.

## C++ Standard Template Library (STL) – [Priority queue]

In the last post we discussed about C++ Standard Template Library (STL) Linked List. In this post we would learn about STL Priority queue and using it as Max/Min Heap. Priority Queue A priority queue is a data structure for maintaining a set of elements having an associated value. Priority Queue […]

## Huffman Code Explained using Heap [Introduction to Algorithms book]

Huffman codes are a widely used technique for compressing data. Huffman codes is a greedy algorithm to build up an optimal way of representing each character as a binary string. Suppose we have a 10,000 character data file that we wish to store. And we observe a character ‘a’ occurs very […]

## How to find k nearest neighbors of a given point from a set of points in a plane?

Problem Statement Let’s given n points in a plane. We’ve to find k nearest neighbors of a given point ‘p’ from the given n points. Problem Naive Solution O(nlogn) Let’s call the given point be P and set of points be S. Iterate over S and find euclidean distance between each […]