Trees mind map

Traversals, BSTs, and recursive tree walks.

Core idea: Define what one subtree returns; traversal order follows from when that answer is needed.

Mnemonic: Define return → order → combine · Cost: O(n) nodes · O(h) call stack

Return: Traversal & subtree summary

Signal: The parent answer depends on height, path, validity, or child state.

Move: Choose pre/in/postorder, then make one recursive call contract combine both children.

Examples: Tree Traversals, Diameter, Maximum Path Sum

Layer: Breadth-first search

Signal: The answer is grouped by depth or needs the nearest level first.

Move: Snapshot queue size, process one level, and enqueue children for the next.

Examples: Level Order, Right Side View, Complete Tree

Order: BST invariant

Signal: Left < node < right lets one comparison discard a subtree.

Move: Carry bounds or exploit sorted inorder order instead of searching both sides.

Examples: Validate BST, Kth Smallest, BST Successor

Relate: Paths, ancestry & encoding

Signal: Two targets meet, a path must be reconstructed, or shape must persist.

Move: Bubble target evidence upward or record values with explicit null markers.

Examples: Lowest Common Ancestor, Tree Directions, Serialize Tree

Every mind map