Add heap module: array min/max heap with dry runs and bottom-up heapify, PriorityQueue comparators and traps, heap sort, 10 interview problems with brute-force cross-checks (17 tests, 23 transcripts)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4HkWoC7hLzk61vZa8
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
Min-heap: offer [35, 20, 50, 10, 40, 5] one at a time
|
||||
=====================================================
|
||||
|
||||
offer(35) placed at index 0 [35]
|
||||
reached the root [35]
|
||||
offer(20) placed at index 1 [35, 20]
|
||||
parent a[0]=35 > 20 swap 1 <-> 0
|
||||
reached the root [20, 35]
|
||||
offer(50) placed at index 2 [20, 35, 50]
|
||||
parent a[0]=20 <= 50 stop
|
||||
offer(10) placed at index 3 [20, 35, 50, 10]
|
||||
parent a[1]=35 > 10 swap 3 <-> 1
|
||||
parent a[0]=20 > 10 swap 1 <-> 0
|
||||
reached the root [10, 20, 50, 35]
|
||||
offer(40) placed at index 4 [10, 20, 50, 35, 40]
|
||||
parent a[1]=20 <= 40 stop
|
||||
offer(5) placed at index 5 [10, 20, 50, 35, 40, 5]
|
||||
parent a[2]=50 > 5 swap 5 <-> 2
|
||||
parent a[0]=10 > 5 swap 2 <-> 0
|
||||
reached the root [5, 20, 10, 35, 40, 50]
|
||||
|
||||
final array : [5, 20, 10, 35, 40, 50]
|
||||
java.util.PriorityQueue shows: [5, 20, 10, 35, 40, 50]
|
||||
Reference in New Issue
Block a user