Binary Tree: Interview Questions and Practice Problems
Published in
5 min readAug 23, 2018
A Binary Tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child, and the topmost node in the tree is called the root.
In this post, we have listed out commonly asked interview questions that use binary tree:
- Inorder Tree Traversal
- Preorder Tree Traversal
- Postorder Tree Traversal
- Check if two binary trees are identical or not
- Print bottom view of a binary tree
- Print top view of a binary tree
- In-place convert a binary tree to its sum tree
- Determine whether the given binary tree nodes are cousins of each other
- Print cousins of a given node in a binary tree
- Check if a binary tree is a sum tree or not
- Combinations of words formed by replacing given numbers with corresponding alphabets
- Determine whether a binary tree is a subtree of another binary tree
- Find the diameter of a binary tree
- Check if a binary tree is symmetric or not
- Convert a binary tree to its mirror
- Determine if a binary tree can be converted to another by doing any number of swaps of children
- Find the Lowest Common Ancestor (LCA) of two nodes in a binary tree
- Print all paths from the root to leaf nodes of a binary tree
- Find ancestors of a given node in a binary tree
- Find distance between given pairs of nodes in a binary tree
- Find the diagonal sum of a binary tree
- Sink nodes containing zero to the bottom of a binary tree
- Convert a binary tree to a full tree by removing half nodes
- Truncate a binary tree to remove nodes that lie on a path having a sum less than `k`
- Find maximum sum root to leaf path in a binary tree
- Check if a binary tree is height-balanced or not
- Convert binary tree to Left-child right-sibling binary tree
- Print all paths from leaf to root node of a binary tree
- Iteratively print the leaf to root path for every leaf node in a binary tree
- Build a binary tree from a parent array
- Find all nodes at a given distance from leaf nodes in a binary tree
- Count all subtrees having the same value of nodes in a binary tree
- Find the maximum difference between a node and its descendants in a binary tree
- Find the maximum sum path between two leaves in a binary tree
- Construct a binary tree from inorder and preorder traversal
- Construct a binary tree from inorder and postorder traversals
- Construct a binary tree from inorder and level order sequence
- Construct a full binary tree from the preorder sequence with leaf node information
- Construct a full binary tree from a preorder and postorder sequence
- Find postorder traversal of a binary tree from its inorder and preorder sequence
- Set next pointer to the inorder successor of all nodes in a binary tree
- Find preorder traversal of a binary tree from its inorder and postorder sequence
- Find the difference between the sum of all nodes present at odd and even levels in a binary tree
- Clone a binary tree with random pointers
- Threaded Binary Tree — Overview and Implementation
- Determine if a binary tree satisfies the height-balanced property of a red–black tree
- Construct an ancestor matrix from a binary tree
- Find all possible binary trees having the same inorder traversal
- Perform boundary traversal on a binary tree
- Check if each node of a binary tree has exactly one child
- Evaluate a Binary Expression Tree
- Construction of an expression tree
- Fix children-sum property in a binary tree
- Maximum path sum in a binary tree
- Create a mirror of an m–ary tree
- Print a two-dimensional view of a binary tree
- Construct a binary tree from an ancestor matrix
- Determine whether a given binary tree is a BST or not
- Find inorder successor for the given key in a BST
- Fix a binary tree that is only one swap away from becoming a BST
- Find the size of the largest BST in a binary tree
- Print binary tree structure with its contents in C++
- Maximum Independent Set Problem
- Huffman Coding Compression Algorithm
- Construct a Cartesian tree from an inorder traversal
- Calculate the height of a binary tree with leaf nodes forming a circular doubly linked list
- Link nodes present in each level of a binary tree in the form of a linked list
- Convert a ternary tree to a doubly-linked list
- Extract leaves of a binary tree into a doubly-linked list
- Find the vertical sum of a binary tree
- In-place convert a binary tree to a doubly-linked list
- Check whether the leaf traversal of given binary trees is the same or not
- Efficiently print all nodes between two given levels in a binary tree
- Calculate the height of a binary tree
- Delete a binary tree
- Level order traversal of a binary tree
- Spiral order traversal of a binary tree
- Reverse level order traversal of a binary tree
- Print all nodes of a perfect binary tree in a specific order
- Print left view of a binary tree
- Find the next node at the same level as the given node in a binary tree
- Check if a binary tree is a complete binary tree or not
- Print diagonal traversal of a binary tree
- Print corner nodes of every level in a binary tree
- Invert Binary Tree
- Convert a binary tree into a doubly-linked list in spiral order
- Check if a binary tree is a min-heap or not
- Invert alternate levels of a perfect binary tree
- Perform vertical traversal of a binary tree
- Compute the maximum number of nodes at any level in a binary tree
- Print right view of a binary tree
- Find the minimum depth of a binary tree
- Depth-First Search (DFS) vs Breadth-First Search (BFS)
- Print nodes of a binary tree in vertical order
Thanks for reading.