# Category Archives: Advanced Data Structure

## Longest Common Prefix using Trie

Given a set of strings, find the longest common prefix. Input : {“geeksforgeeks”, “geeks”, “geek”, “geezer”} Output : “gee” Input : {“apple”, “ape”, “april”} Output… Read More »

## Smallest Subarray with given GCD

Given an array arr[] of n numbers and an integer k, find length of the minimum sub-array with gcd equals to k. Example: Input: arr[]… Read More »

## GCDs of given index ranges in an array

Given an array a[0 . . . n-1]. We should be able to efficiently find the GCD from index qs (query start) to qe (query… Read More »

## Disjoint Set Data Structures

Consider a situation with a number of persons and following tasks to be performed on them. Add a new friendship relation, i.e., a person x… Read More »

## Tarjan’s off-line lowest common ancestors algorithm

Prerequisite : LCA basics, Disjoint Set Union by Rank and Path Compression We are given a tree(can be extended to a DAG) and we have… Read More »

## Cartesian Tree Sorting

Prerequisites : Cartesian Tree Cartesian Sort is an Adaptive Sorting as it sorts the data faster if data is partially sorted. In fact, there are… Read More »

## Cartesian Tree

A Cartesian tree is a tree data structure created from a set of data that obeys the  following structural invariants: The tree obeys in the min (or max) heap property – each node is less (or greater) than its children. An inorder traversal of the nodes yields the values in the same order in which they appear in the initial sequence. Suppose we have an input array- {5,10,40,30,28}. Then the max-heap Cartesian Tree would be. A min-heap Cartesian… Read More »

## Sparse Set

How to do the following operations efficiently if there are large number of queries for them. Insertion Deletion Searching Clearing/Removing all the elements. One solution… Read More »

## Persistent data structures

All the data structures discussed here so far are non-persistent (or ephermal). A persistent data structure is a data structure that always preserves the previous… Read More »

## Centroid Decomposition of Tree

Background : What is centroid of Tree? Centroid of a Tree is a node which if removed from the tree would split it into a… Read More »

## Gomory-Hu Tree | Set 1 (Introduction)

Background : In a flow network, an s-t cut is a cut that requires the source ‘s’ and the sink ‘t’ to be in different… Read More »

## ­­kasai’s Algorithm for Construction of LCP array from Suffix Array

Background Suffix Array : A suffix array is a sorted array of all suffixes of a given string. Let the given string be “banana”. 0… Read More »

## Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)

We have discussed below data structures in previous two sets. Set 1 : Overview of Array, Linked List, Queue and Stack. Set 2 : Overview… Read More »

## Heavy Light Decomposition | Set 2 (Implementation)

We strongly recommend to refer below post as a prerequisite of this. Heavy Light Decomposition | Set 1 (Introduction) In the above post, we discussed… Read More »

## Heavy Light Decomposition | Set 1 (Introduction)

Heavy Light decomposition (HLD) is one of the most used techniques in competitive programming. Example Problem: Let us understand Heavy-light decomposition (HLD) with the help… Read More »