Add bst module: recursive and iterative insert/search, three delete cases, BST validation, kth smallest, LCA, floor/ceiling, balance check and 10 problems cross-checked against brute force (25 tests, 16 transcripts)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6vDJ5fWY5uEZaJFNi
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
Lowest common ancestor on the sample tree
|
||||
=========================================
|
||||
|
||||
lca(20, 35):
|
||||
at 50: both smaller, go left
|
||||
at 30: paths split here, answer 30
|
||||
lca(35, 65):
|
||||
at 50: paths split here, answer 50
|
||||
lca(60, 65):
|
||||
at 50: both larger, go right
|
||||
at 70: both smaller, go left
|
||||
at 60: paths split here, answer 60
|
||||
|
||||
lca(20, 99), with 99 absent, returns 50 (a wrong-looking answer: check presence first)
|
||||
Reference in New Issue
Block a user