Expert Funda Leetcode Top 50 IQ Contact About

FAANG Interview Binary Tree

FAANG Interview Binary Tree

Binary Tree

Important Questions

Quick Study Guide

A basic instinct for solving DFS based questions is to do a recursive call and for all BFS (level order traversal) is to make a queue and iterate, but also think upon how to iterate in DFS (Hint: think on stack) and recurse in BFS based.

First of all you should look at traversal problems:

A variation for LevelOrder can be:

Solving these questions will help you get familiarized with basic btree dfs and bfs traversals.

Intuition for Level Order Traversal iteratively using queue: Construct a queue of type: TreeNode queue q, initially push the given root in it. Iterate through the queue until empty: Store the current size of queue tempSize, this will be the size of the current level of the tree. Now we need to traverse this level so iterate for tempSize>=0 : Pop the current element and apply the needed operation for the same and if left or right child exist then pass them to the queue.

Now, some basic Binary Tree problems that will help your thinking process:

Binary Search Tree: Use the property of BST judiciously (the left subtree will always contain nodes with value less than root's value and right subtree will contain nodes with value greater than root's value)

Path problems

You are given root, you have to perform operations on a path, (path is root to leaf).
Think upon the type of traversal you will apply when going from root to leaf:

*Last two problems here are utmost important

Next is, given a combination of preorder, postorder and inorder traversals,
you need to construct a binary tree/BST:
Hint: Observe in each traversal method, position of root and head of right and left subtrees

View problems

Try thinking for left, bottom and top too!

Binary Tree Right Side View

Lowest Common Ancestor problems

You are given two nodes and you have to return their ancestor at as least depth possible, these are problems are a must todo:

Validate trees

Some miscellaneous problems that you should definitely look through:

I will be updating this list on finding more important questions or any pattern that I find.