[Leetcode for Interviews] BinaryTree Traversal – DFS & BFS

After introducing traversing trees using BFS and DFS in Tree Traversal – Recursively & Iteratively – Preorder, Inorder, Postorder, it’s time to get some practices! Here are Leetcode questions that appear frequently during tech interviews.

Leetcode problems: https://leetcode.com/problemset/all/

QuestionDifficultyNotes
102. Binary Tree Level Order TraversalMediumTypical BFS traversal
94. Binary Tree Inorder TraversalMediumTypical inorder traversal
144. Binary Tree Preorder TraversalMediumTypical preorder traversal
145. Binary Tree Postorder TraversalHardTypical postorder traversal
98. Validate Binary Search TreeMedium
105. Construct Binary Tree from Preorder and Inorder TraversalMediumIt helps to enhance the comprehension of tree traversals as you need to consider both preorder and inorder at the same time
106. Construct Binary Tree from Inorder and Postorder TraversalMediumIt helps to enhance the comprehension of tree traversals as you need to consider both inorder and postorder at the same time
314. Binary Tree Vertical Order TraversalMediumIt requires BFS to ensure ‘top to bottowm’ and Queue to ensure ‘left to right’
366. Find Leaves of Binary TreeMediumh(node)=1+max(h(node.left),h(node.right)) where h(node) returns the height of the node
Leetcode for Interview – Tree Traversals

Feel free to comment here if you have any confusion or suggestions!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments