## Sum of all odd nodes in the path connecting two given nodes

Given a binary tree and two nodes of that binary tree. Find the sum of all nodes with odd values in the path connecting the… Read More »

## Lowest Common Ancestor in Parent Array Representation

Given a binary tree represented as parent array, find Lowest Common Ancestor between two nodes ‘m’ and ‘n’. In the above diagram, LCA of 10… Read More »

## Remove edges connected to a node such that the three given nodes are in different trees

Given a binary tree and 3 nodes a, b and c, the task is to find a node in the tree such that after removing… Read More »

## Queries to find distance between two nodes of a Binary tree – O(logn) method

Given a binary tree, the task is to find the distance between two keys in a binary tree, no parent pointers are given. Distance between… Read More »

## Queries to find distance between two nodes of a Binary tree

Given a binary tree, the task is to find the distance between two keys in a binary tree, no parent pointers are given. The distance… Read More »

## Lowest Common Ancestor in a Binary Tree | Set 3 (Using RMQ)

Given a rooted tree, and two nodes which is in the tree, find the Lowest common ancestor of both the nodes. The LCA for two… Read More »

## Shortest distance between two nodes in BST

Given a Binary Search Tree and two keys in it. Find the distance between two nodes with given two keys. It may be assumed that… Read More »

## Print common nodes on path from root (or common ancestors)

Given a binary tree and two nodes, the task is to Print all the nodes that are common for 2 given nodes in a binary… Read More »

## Print the path common to the two paths from the root to the two given nodes

Given a binary tree with distinct nodes(no two nodes have the same have data values). The problem is to print the path common to the… Read More »

## Sqrt (or Square Root) Decomposition | Set 2 (LCA of Tree in O(sqrt(height)) time)

Prerequisite : Introduction and DFS The task is to find LCA of two given nodes in a tree (not necessarily a Binary Tree). In previous… Read More »

## Maximum element between two nodes of BST

Given an array of N elements and two integers A, B which belongs to the given array. Create a Binary Search Tree by inserting element… Read More »

## LCA for general or n-ary trees (Sparse Matrix DP approach < O(nlogn), O(logn)>)

In previous posts, we have discussed how to calculate the Lowest Common Ancestor (LCA) for a binary tree and a binary search tree (this, this… Read More »

## Longest Common Extension / LCE | Set 3 (Segment Tree Method)

Prerequisites : LCE(Set 1), LCE(Set 2), Suffix Array (n Log Log n), Kasai’s algorithm and Segment Tree The Longest Common Extension (LCE) problem considers a… Read More »

## Longest Common Extension / LCE | Set 1 (Introduction and Naive Method)

The Longest Common Extension (LCE) problem considers a string s and computes, for each pair (L , R), the longest sub string of s that… 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 »