Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6vDJ5fWY5uEZaJFNi
31 lines
504 B
Plaintext
31 lines
504 B
Plaintext
Delete case 3: a node with two children (the root)
|
|
==================================================
|
|
|
|
before:
|
|
50
|
|
L: 30
|
|
L: 20
|
|
R: 40
|
|
L: 35
|
|
R: 70
|
|
L: 60
|
|
R: 65
|
|
R: 80
|
|
|
|
delete 50:
|
|
at 50: equal, found after 1 nodes
|
|
two children: successor = smallest key in right subtree = 60
|
|
copy 60 into the node, then delete 60 from the right subtree
|
|
|
|
after:
|
|
60
|
|
L: 30
|
|
L: 20
|
|
R: 40
|
|
L: 35
|
|
R: 70
|
|
L: 65
|
|
R: 80
|
|
|
|
inorder: [20, 30, 35, 40, 60, 65, 70, 80]
|