Binary Trees study guide
Kartik Kathuria
Cloud Engineer-1 at Insight | 15k+ LinkedIn Family | ?? 2x Azure Certified | AZ-900 | AZ-204 | Microsoft PowerApps Developer | Azure DevOps | API Development | Spring Boot | Online Programming Instructor | Azure Trainer
Prerequisites?that you should be familiar with before :?Recursion, stack, queue
A basic instinct for solving DFS based questions is to do a recursive call and for all BFS(level order traversal) is to make 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:?ZigZag level order traversal?and?Binary Tree Level Order Traversal II
Solving these questions will help you get familiarized with basic btree dfs and bfs traversals.
Intuition for Level Order Traversal?iteratively using 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:
领英推荐
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!
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.
SDE-3 @Walmart | Code Delivery Guy ?? | 28K+ supporters
1 年Helpful.. ??
Junior Engineer @ Daxko | Ex- Able (YC W20) | Programmer
1 年bhai tum prepare kr rahe ho kya MAANGA ki??????
Cloud Engineer-1 at Insight | 15k+ LinkedIn Family | ?? 2x Azure Certified | AZ-900 | AZ-204 | Microsoft PowerApps Developer | Azure DevOps | API Development | Spring Boot | Online Programming Instructor | Azure Trainer
1 年Tagging Abhijeet Soni Saif M. Ankit Kumar ADARSH CHETAN Rajesh Kumar Aditya Verma Raj Vikramaditya Love Babbar Anuj Kumar Sharma for better reach.