HomeBinary Trees
Binary Trees
Traversals and divide-and-conquer over left and right subtrees.
42 shown
- Tree TraversalsInorder · Preorder · PostorderanimatedEasy
- Maximum Depth1 + max(left, right)animatedEasy
- Diameter of Binary TreeLongest path through any nodeanimatedMedium
- Invert Binary TreeSwap children everywhereanimatedEasy
- Lowest Common AncestorWhere the two search paths splitanimatedMedium
- Practice problems
- Introduction to TreesA root, and up to two children eachanimatedEasy
- Binary Tree Representation in JavaA node class with two referencesanimatedEasy
- Pre, Post, Inorder in one traversalOne stack, a visit counter per nodeanimatedEasy
- Preorder TraversalRoot, then left, then rightanimatedEasy
- Inorder Traversal of Binary TreeLeft, then root, then rightanimatedEasy
- Postorder TraversalLeft, then right, then rootanimatedEasy
- Level Order TraversalA queue, one level per passanimatedEasy
- Iterative Preorder Traversal of Binary TreeA stack, right child pushed firstanimatedEasy
- Iterative Inorder Traversal of Binary TreeDescend left, pop, then go rightanimatedEasy
- Post-order Traversal of Binary Tree using 2 stackBuild root-right-left, then reverse itanimatedEasy
- Post-order Traversal of Binary Tree using 1 stackTrack the last node you emittedanimatedEasy
- Preorder, Inorder, and Postorder Traversal in one TraversalThe same three-state stack walkanimatedEasy
- Maximum Depth in BTOne plus the deeper childanimatedMedium
- Check for balanced binary treeReturn the height, or a failure sentinelanimatedMedium
- Maximum path sumA path may bend once, at its highest nodeanimatedMedium
- Check if two trees are identical or notSame value, same shape, recursivelyMedium
- Zig Zag or Spiral TraversalLevel order, reversing alternate rowsanimatedMedium
- Boundary TraversalLeft edge, leaves, right edge reversedMedium
- Vertical Order TraversalGive each node a (column, row) coordinateanimatedMedium
- Top View of BTFirst node seen in each columnanimatedMedium
- Bottom view of BTLast node seen in each columnanimatedMedium
- Right/Left View of Binary TreeLast node of each levelanimatedMedium
- Symmetric Binary TreeCompare left against right, mirroredMedium
- Print root to leaf path in BTAppend on the way down, remove on the way backMedium
- LCA in BTThe node where the two searches meetanimatedHard
- Maximum Width of BTIndex nodes as if the tree were an arrayanimatedMedium
- Children Sum Property in Binary TreePush values down, then fix on the way upMedium
- Print all nodes at a distance of K in BTAdd parent pointers, then BFS outwardHard
- Minimum time taken to burn the BT from a given NodeBFS from the target, counting levelsHard
- Count total nodes in a complete BTA perfect subtree can be counted by formulaEasy
- Requirements needed to construct a unique BTInorder plus one other orderMedium
- Construct a BT from Preorder and InorderPreorder gives the root, inorder splits the sidesHard
- Construct the Binary Tree from Postorder and Inorder TraversalPostorder gives the root, read from the endHard
- Serialize and De-serialize BTPreorder with explicit nullsHard
- Morris Preorder Traversal of a Binary TreeThread the tree instead of using a stackHard
- Morris Inorder Traversal of a Binary TreeThe same threads, recorded laterHard
- Flatten Binary Tree to Linked ListRight-child chain in preorderMedium