Category Archives: Advanced Data Structure

Longest Common Prefix | Set 5 (Using Trie)

Given a set of strings, find the longest common prefix. Input : {“geeksforgeeks”, “geeks”, “geek”, “geezer”} Output : “gee” Input : {“apple”, “ape”, “april”} Output : “ap” Previous Approaches : Word by Word Matching , Character by Character Matching, Divide and Conquer , Binary Search. In this article, an approach using Trie date structure is… 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 very few sorting algorithms that make use of this fact. For example consider the array {5, 10, 40, 30, 28}. The input data is partially sorted too as only one… Read More »

Cartesian Tree

A Cartesian tree is a tree data structure created from a set of data that obeys the  following structural invariants:

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 is to use a Self-Balancing Binary Search Tree like Red-Black Tree, AVL Tree, etc. Time complexity of this solution for insertion, deletion and searching is O(Log n). We can also… Read More »