# Tag Archives: LCA

## Find distance between two nodes in the given Binary tree for Q queries

Given a binary tree having N nodes and weight of N-1 edges. The distance between two nodes is the sum of the weight of edges… Read More »

## Count of all prime weight nodes between given nodes in the given Tree

Given a weighted tree containing N nodes, and two nodes u and v, the task is to find the count of nodes having prime weight… Read More »

## Query to find the maximum and minimum weight between two nodes in the given tree using LCA.

Given a tree, and the weights of all the node. Each query contains two integers u and v, the task is to find the minimum… Read More »

## Lowest Common Ancestor for a Set of Nodes in a Rooted Tree

Given a rooted tree with N nodes, the task is to find the Lowest Common Ancestor for a given set of nodes V of that… Read More »

## Least Common Ancestor of any number of nodes in Binary Tree

Given a binary tree (not a binary search tree) and any number of Key Nodes, the task is to find the least common ancestor of… Read More »

## Queries to check if the path between two nodes in a tree is a palindrome

Given a tree with N nodes and N – 1 edges. Each edge of the tree is labeled by a string of lowercase english alphabets.… Read More »

## Check whether the given node is in the path between the nodes U and V

Given three vertices U, V and R of a binary tree, the task is to check whether R lies in the path between U and… Read More »

## LCA in a tree using Binary Lifting Technique

Given a binary tree, the task is to find the Lowest Common Ancestor of the given two nodes in the tree. Let G be a… Read More »

## Minimum and maximum node that lies in the path connecting two nodes in a Binary Tree

Given a binary tree and two nodes a and b, the task is to print the minimum and the maximum node value that lies in… Read More »

## 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 are in the tree, find the Lowest common ancestor of both the nodes. The LCA for two… Read More »