## Find Lowest Common Ancestor (LCA) of Two Nodes in a Binary Tree

Given a binary tree and two nodes x and y in it, find lowest common ancestor (LCA) of x and y in it.

Coding made easy

Binary Trees

Given a binary tree and two nodes x and y in it, find lowest common ancestor (LCA) of x and y in it.

Given a binary tree, write iterative and recursive solution to traverse the tree using in-order traversal. Unlike linked lists, one-dimensional arrays and other linear data structures, which are traversed in linear order, trees may be traversed in multiple ways in depth-first order (in-order, pre-order and post-order) or breadth-first order (level order traversal). Beyond these …

Given a binary tree, write iterative and recursive solution to traverse the tree using pre-order traversal. Unlike linked lists, one-dimensional arrays and other linear data structures, which are traversed in linear order, trees may be traversed in multiple ways in depth-first order (pre-order, pre-order and pre-order) or breadth-first order (level order traversal). Beyond these …

Given a binary tree, write iterative and recursive solution to traverse the tree using post-order traversal. Unlike linked lists, one-dimensional arrays and other linear data structures, which are traversed in linear order, trees may be traversed in multiple ways in depth-first order (post-order, pre-order and post-order) or breadth-first order (level order traversal). Beyond these …

Given a binary tree, write an efficient algorithm to determine if it can be converted to another binary tree by doing any number of swaps of its right and left branches.

Given a binary tree, write an efficient algorithm to convert binary tree to its mirror.

Given a binary tree, write an efficient algorithm to check if it is symmetric binary tree or not. i.e. left subtree and right subtree are mirror images or each other.

Given a binary tree, write an efficient algorithm to compute the diameter of it. The diameter of a binary tree is equal to number of nodes on the longest path between any two leaves in it.

Given a binary tree, determine if it is a subtree of another binary tree or not. A subtree of a tree T is a tree consisting of a node in T and all of its descendants in T.

Given a set of positive numbers, find all possible combinations of words formed by replacing the continuous digits with corresponding character of English alphabet. i.e. subset {1} can be replaced by A, {2} can be replaced by B, {1, 0} can be replaced J, {2, 1} can be replaced U, etc..

Given a binary tree, check if it is a sum tree or not. In a sum tree, value at each non-leaf node is equal to the sum of all elements present in its left and right subtree. The value of a leaf node can be anything.

Given a binary tree, in-place convert it to its sum tree. In a sum tree, value at each node is equal to the sum of all elements present in its left and right subtree. The value of an empty node is considered as 0.