Tag Archives: Segment-Tree

Given an empty set initially and a number of queries on it, each possibly of the following types: Insert – Insert a new element ‘x’.… 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 »

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 »

Top 10 Algorithms and Data Structures for Competitive Programming

In this post “Important top 10 algorithms and data structures for competitive coding “. Topics : Graph algorithms Dynamic programming Searching and Sorting: Number theory… Read More »

Find LCA in Binary Tree using RMQ

The article describes an approach to solving the problem of finding the LCA of two nodes in a tree by reducing it to a RMQ… Read More »

Range Minimum Query (Square Root Decomposition and Sparse Table)

We have an array arr[0 . . . n-1]. We should be able to efficiently find the minimum value from index L (query start) to… Read More »

Lazy Propagation in Segment Tree

Segment tree is introduced in previous post with an example of range sum problem. We have used the same “Sum of given Range” problem to… Read More »

Largest Rectangular Area in a Histogram | Set 1

Find the largest rectangular area possible in a given histogram where the largest rectangle can be made of a number of contiguous bars. For simplicity,… Read More »

Segment Tree | Set 2 (Range Minimum Query)

We have introduced segment tree with a simple example in the previous post. In this post, Range Minimum Query problem is discussed as another example… Read More »

Segment Tree | Set 1 (Sum of given range)

Let us consider the following problem to understand Segment Trees. We have an array arr[0 . . . n-1]. We should be able to 1… Read More »