Download presentation
Presentation is loading. Please wait.
1
The Potential Method
2
Deque with stacks size=7 13 S1S1 S2S2 push(x,D): push(x,S 1 ) 5 4 17 21 8 7 push(2,D)
3
Implementation with stacks size=8 2 13 S1S1 S2S2 push(x,D): push(x,S 1 ) 5 4 17 21 8 7 push(2,D)
4
Pop size=8 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) 2 13 5 4 17 21 8 7 pop(D)
5
Pop size=7 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) 13 5 4 17 21 8 7 pop(D) pop(D)
6
Pop size=6 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) 5 4 17 21 8 7 pop(D) pop(D)
7
Pop 17 21 8 7 size=6 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D) 5 4
8
Delete from Queue 17 21 8 7 size=5 S1S1 S2S2 4 Pop 17 21 8 size=4 S1S1 S2S2 4
9
The potential method
11
If then.
12
PUSH The same for POP without split
13
5 4 17 21 8 7 S1S1 S2S2 17 21 8 7 S1S1 S2S2 5 4 s=6 s/32s/3 POP that calls SPLIT
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.