Trees and Tries Python lessons
Traversal, recursion on hierarchies, binary-search-tree rules, prefix lookup, and subtree reasoning.
Core concepts
Problem-solving patterns
- tree · BFS
- tree · depth
- BST · bounds
- binary tree · recursion · LeetCode pattern
- BST · inorder · company screen
What this topic builds
Learn the idea once, trace it through two verified cases, then explain why your approach works.
All 13 lessons in this topic
Work from top to bottom to build each concept gradually.
- #137Traverse a binary tree by levelsBeginnerPremium
Print each depth of a small complete tree on its own line.
- #138Find binary-tree maximum depthIntermediatePremium
Find the depth of a tree whose longest path contains three nodes.
- #139Validate a binary search treeIntermediatePremium
Confirm that all nodes obey the global binary-search-tree ordering rule.
- #140Find lowest common ancestorIntermediatePremium
Find the lowest node whose subtree contains both requested values.
- #141Find kth smallest value in a BSTAdvancedPremium
Return the third value in the BST's increasing order.
- #142Serialize and deserialize a binary treeAdvancedPremium
Serialize a sparse tree, deserialize it, and show the preserved tokens.
- #143Build a tree from preorder and inorderAdvancedPremium
Reconstruct a tree and print its level-order values.
- #144View a binary tree from the rightInterview-LevelPremium
Return the node visible from the right at every tree level.
- #145Calculate binary-tree diameterInterview-LevelPremium
Find the longest edge-count path between any two nodes.
- #146List root-to-leaf target pathsInterview-LevelPremium
List every root-to-leaf path whose values reach the target.
- #147Implement a prefix trieInterview-LevelPremium
Insert words, then distinguish exact matches from valid prefixes.
- #148Find dictionary words in a boardInterview-LevelPremium
Find all dictionary words that can be formed by adjacent cells without reuse.
- #149Find maximum binary-tree path sumInterview-LevelPremium
Find the greatest sum along any connected path in the tree.