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,26 @@
|
||||
Insert 50 30 70 20 40 60 80 35 65, one key at a time
|
||||
====================================================
|
||||
|
||||
insert 50: -> becomes the root
|
||||
insert 30: 50 L -> new left child of 50
|
||||
insert 70: 50 R -> new right child of 50
|
||||
insert 20: 50 L, 30 L -> new left child of 30
|
||||
insert 40: 50 L, 30 R -> new right child of 30
|
||||
insert 60: 50 R, 70 L -> new left child of 70
|
||||
insert 80: 50 R, 70 R -> new right child of 70
|
||||
insert 35: 50 L, 30 R, 40 L -> new left child of 40
|
||||
insert 65: 50 R, 70 L, 60 R -> new right child of 60
|
||||
insert 40 again: no change (set semantics), still 9 nodes
|
||||
|
||||
Tree (recursive and iterative insert give the same outline):
|
||||
50
|
||||
L: 30
|
||||
L: 20
|
||||
R: 40
|
||||
L: 35
|
||||
R: 70
|
||||
L: 60
|
||||
R: 65
|
||||
R: 80
|
||||
|
||||
inorder: [20, 30, 35, 40, 50, 60, 65, 70, 80]
|
||||
Reference in New Issue
Block a user