Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6nxynun5JFivebVb1
25 lines
1.2 KiB
Plaintext
25 lines
1.2 KiB
Plaintext
Operation counts (counted, not timed)
|
|
=====================================
|
|
|
|
nextGreater on a strictly decreasing array (the worst case for the scan-right version)
|
|
n scan-right compares stack compares stack push+pop
|
|
1000 499500 999 1000
|
|
10000 49995000 9999 10000
|
|
100000 4999950000 99999 100000
|
|
|
|
nextGreater on random values (n = 100000): every index is pushed once and popped at most once
|
|
pushes = 100000, pops = 99985, comparisons = 199977 (bound: comparisons <= 2n = 200000)
|
|
|
|
QueueViaStacks: n enqueues followed by n dequeues
|
|
n total element moves moves in the 1st dequeue
|
|
1000 1000 1000
|
|
10000 10000 10000
|
|
100000 100000 100000
|
|
one dequeue can cost n moves, but each element moves exactly once, so n enqueues + n dequeues cost 3n steps in all
|
|
|
|
StackViaQueue: n pushes
|
|
n total rotations n(n-1)/2
|
|
100 4950 4950
|
|
1000 499500 499500
|
|
5000 12497500 12497500
|