Trees and BST in Java
Tree node
class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int val) { this.val = val; }
}Problems to practice
- Inorder traversal
- Preorder traversal
- Postorder traversal
- Level order traversal
- Maximum depth
- Diameter of tree
- LCA
- Validate BST
- Path Sum
Example: DFS traversal
void inorder(TreeNode root) {
if (root == null) return;
inorder(root.left);
System.out.print(root.val + " ");
inorder(root.right);
}Interview guidance
BST property helps with search and sorted traversal.
Can you explain it without the notes?
Trees and BST in Java
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Tree node
Turn this concept into a clear answer.
Practice this conceptAdapted from 15_DSA_JAVA.md · “7. Trees and BST in Java”. Examples are study fragments; framework behavior can depend on your version.