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:
Claude
2026-12-03 23:32:04 +05:30
parent 6e5764978f
commit 5419e5057d
36 changed files with 1712 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
Ten problems, each against a brute force on random trees (seeded)
=================================================================
1. validate BST: 20000 random binary trees, 7382 were BSTs; bounds and inorder agreed on all; childrenOnly wrongly accepted 417
2. kth smallest: 27427 (tree, k) cases against sorting all keys
3. lowest common ancestor: 18990 pairs against comparing the two root paths
4. range sum: 2000 cases against filtering all keys; sample tree [35, 50] = 125
5. sorted array to balanced BST: every n from 0 to 500 is a balanced BST of minimum height with the same keys
6. inorder successor: 2000 cases against scanning all keys; successor(40) in the sample tree = 50
7. two keys summing to a target: 2000 cases (359 true) against all pairs
8. minimum difference: 1729 trees against all pairs; MIN_VALUE and MAX_VALUE give 4294967295 (needs long)
9. recover two swapped keys: 1834 damaged trees, all restored
10. trim to a range: 2000 cases against filtering all keys, result still a BST; sample trimmed to [35, 65] = [35, 40, 50, 60, 65]