Delete the last leaf node in a Binary Tree

Given a Binary Tree, the task is to find and DELETE the last leaf node. The leaf node is a node with no children. The… Read More »

Duplicate subtree in Binary Tree | SET 2

Given a binary tree, the task is to check whether the binary tree contains a duplicate sub-tree of size two or more. Input: A /… Read More »

Convert ternary expression to Binary Tree using Stack

Given a string str that contains a ternary expression which may be nested. The task is to convert the given ternary expression to a binary… Read More »

Check which player visits more number of Nodes

Given a tree with N nodes. Two players A and B start from node 1 and node N respectively. A can visit all the adjacent… Read More »

Insertion in n-ary tree in given order and Level order traversal

Given a set of parent nodes where the index of the array is the child of each Node value, the task is to insert the… Read More »

Red-Black Trees | Top-Down Insertion

In Bottom-Up insertion of Red-Black Trees, “simple” Binary Search Tree insertion is used, followed by correction of the RB-Tree Violations on the way back up… Read More »

m-WAY Search Trees | Set-1 ( Searching )

The m-way search trees are multi-way trees which are generalised versions of binary trees where each node contains multiple elements. In an m-Way tree of… Read More »

Implementing a BST where every node stores the maximum number of nodes in the path till any leaf

Given an array of values. The task is to implement a Binary Search Tree using values of the array where every node stores the maximum… Read More »

Number of distinct pair of edges such that it partitions both trees into same subsets of nodes

Given two trees each of N nodes. Removing an edge of the tree partitions the tree in two subsets. Find the total maximum number of… Read More »

String Range Queries to find the number of subsets equal to a given String

Given a string S of length N, and M queries of the following type: Type 1: 1 L x, Indicates update Lth index of string… Read More »

Queries for number of distinct elements in a subarray | Set 2

Given an array arr[] of N integers and Q queries. Each query can be represented by two integers L and R. The task is to… Read More »

Maximum XOR with given value in the path from root to given node in the tree

Given a tree with N distinct nodes from the range [1, n] and two integers x and val. The task is to find the maximum… Read More »

Product of minimum edge weight between all pairs of a Tree

Given a tree with N vertices and N-1 Edges. Let’s define a function F(a, b) which is equal to the minimum edge weight in the… Read More »

Print Bottom-Right View of a Binary Tree

Given a Binary Tree, print Bottom-Right view of it. The Bottom Right view of a Binary Tree is a set of nodes visible when the… Read More »

Find the Deepest Node in a Binary Tree Using Queue STL – SET 2

Given a binary tree. The task is to find the value of the deep­est node in the given binary tree. Examples: Input: Root of below… Read More »