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,31 @@
|
||||
Delete case 2: a node with one child
|
||||
====================================
|
||||
|
||||
before:
|
||||
50
|
||||
L: 30
|
||||
L: 20
|
||||
R: 40
|
||||
L: 35
|
||||
R: 70
|
||||
L: 60
|
||||
R: 65
|
||||
R: 80
|
||||
|
||||
delete 60:
|
||||
at 50: 60 > 50, go right
|
||||
at 70: 60 < 70, go left
|
||||
at 60: equal, found after 3 nodes
|
||||
one child (65): return that child to the parent
|
||||
|
||||
after:
|
||||
50
|
||||
L: 30
|
||||
L: 20
|
||||
R: 40
|
||||
L: 35
|
||||
R: 70
|
||||
L: 65
|
||||
R: 80
|
||||
|
||||
inorder: [20, 30, 35, 40, 50, 65, 70, 80]
|
||||
Reference in New Issue
Block a user