Trees

Master tree traversal, manipulation, and advanced tree algorithms.

Showing 20 of 20 questions
Easy: 0 Medium: 0 Hard: 0
QUESTIONDIFFICULTY
Binary Tree Inorder Traversal
Traverse a binary tree in inorder (left -> root -> right)
Easy
Binary Tree Preorder Traversal
Traverse a binary tree in preorder (root -> left -> right)
Easy
Invert Binary Tree
Invert (mirror) a binary tree by swapping left and right children
Easy
Maximum Depth of Binary Tree
Find the maximum depth (height) of a binary tree
Easy
Postorder Traversal
Traverse binary tree in postorder (left, right, root)
Easy
Boundary Traversal of Binary Tree
Traverse the boundary of a binary tree in anti-clockwise direction.
Medium
Construct Binary Tree from Preorder and Inorder Traversal
Construct a binary tree from preorder and inorder traversal sequences.
Medium
Convert Sorted Array to Binary Search Tree
Convert a sorted array to a height-balanced binary search tree.
Medium
Count Good Nodes in Binary Tree
Count the number of nodes in a binary tree where the path from root to that node has no nodes with values greater than the current node.
Medium
Diameter of Binary Tree
Find the diameter (longest path) of a binary tree.
Medium
Flatten Binary Tree to Linked List
Flatten a binary tree into a linked list in-place using preorder traversal.
Medium
Level Order Traversal
Traverse a binary tree level by level from left to right.
Medium
Lowest Common Ancestor
Find the lowest common ancestor of two nodes in a binary tree.
Medium
Maximum Path Sum
Find the maximum path sum in a binary tree.
Medium
Path Sum
Check if there exists a root-to-leaf path with given sum.
Medium
Print All Root-to-Leaf Paths
Print all root-to-leaf paths in a binary tree
Medium
Symmetric Tree
Check if a binary tree is symmetric around its center.
Medium
Zigzag Level Order Traversal
Traverse a binary tree level by level in zigzag order
Medium
Serialize and Deserialize Binary Tree
Serialize a binary tree to a string and deserialize it back to the original tree
Hard
Vertical Order Traversal of Binary Tree
Traverse a binary tree vertically and return nodes by columns
Hard

Overview

Trees are hierarchical data structures fundamental to many algorithms. This section covers tree traversal, manipulation, and advanced tree-based algorithms.

Key Concepts

  • Tree traversal (inorder, preorder, postorder, level-order)
  • Binary search trees (BST)
  • Tree height and depth
  • Balanced trees
  • Lowest common ancestor
  • Path sum problems

Common Problems

Easy

  • Maximum Depth of Binary Tree
  • Invert Binary Tree
  • Symmetric Tree
  • Same Tree

Medium

  • Binary Tree Level Order Traversal
  • Validate Binary Search Tree
  • Lowest Common Ancestor
  • Path Sum II

Hard

  • Binary Tree Maximum Path Sum
  • Serialize and Deserialize Binary Tree
  • Recover Binary Search Tree

Practice Tips

  1. Recursion first: Most tree problems have elegant recursive solutions
  2. Base cases: Handle null nodes carefully
  3. Traversal choice: Pick the right traversal for the problem
  4. Iterative solutions: Practice stack-based iterative traversals

Resources