# Category Archives: Data Structures

In my previous post, I have explained about longest increasing sub-sequence (LIS) problem in detail. However, the post only covered code related to querying size of… Read More
We recommend reading the following two posts as a prerequisite to this post. Greedy Algorithms | Set 5 (Prim’s Minimum Spanning Tree (MST))  Graph and… Read More
Introduction to Prim’s algorithm: We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm. This algorithm always starts… Read More
Graph is a data structure that consists of the following two components:  A finite set of vertices also called nodes. A finite set of ordered… Read More
Given a Queue data structure that supports standard operations like enqueue() and dequeue(). The task is to implement a Stack data structure using only instances… Read More
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
Pascal’s triangle is a triangular array of binomial coefficients. Write a function that takes an integer value n as input and prints first n lines… Read More
A minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected, undirected graph is a spanning tree with a weight less than… Read More
In the previous post, we introduced union find algorithm and used it to detect cycles in a graph. We used the following union() and find()… Read More
A disjoint-set data structure is defined as a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping)… Read More
Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output may be… Read More
Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output may be… Read More
Given a Binary Tree, write an iterative function to print the Preorder traversal of the given binary tree.Refer to this for recursive preorder traversal of… Read More
Given two numbers represented by two linked lists, write a function that returns the sum of the two linked lists in the form of a… Read More
Given a binary 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5… Read More