The Potential Method. Deque with stacks size=7 13 S1S1 S2S2 push(x,D): push(x,S 1 ) 5 4 17 21 8 7 push(2,D)

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Data Structure HKOI training /4/2010 So Pak Yeung.
1 Persistent data structures. 2 Ephemeral: A modification destroys the version which we modify. Persistent: Modifications are nondestructive. Each modification.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
CS261 Data Structures Single Source Reachability - Edge List Representation.
Sit-in lab 4.  Given a number of strings containing only “a”, “b”, “c”, “d”  Check each string that it follows the pattern a n b m c m d n where m,
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Stacks, Queues, and Deques
Data Structures & Algorithms
1 Abstract Data Types Stack, Queue Amortized analysis Cormen: Ch 10, 17 (11, 18)
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Stacks.
Data Structures from Cormen, Leiserson, Rivest & Stein.
Preorder Traversal with a Stack Push the root onto the stack. While the stack is not empty n pop the stack and visit it.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
1 Abstract Data Types Queue + Dequeue Amortized analysis.
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
Stack and Queue.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
Due: 2007/11/12. Problem 1 Rewrite function Push and Pop (Program 3.10 and 3.12) using an additional variable lastOp as discussed on Page 146. The queue.
Stacks and Queues Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 16 © 2002 Addison Wesley.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Stacks and Queues. Announcements USACO Open competition results are out o Congrats to Johnny for scoring 2nd in the US USACO Finalists are also announced.
Basic Data Structures Stacks. A collection of objects Objects can be inserted into or removed from the collection at one end (top) First-in-last-out.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
Computer Engineering Rabie A. Ramadan Lecture 6.
STACK Data Structure
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1.
CISC220 Spring 2010 James Atlas Lecture 10: Queues.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class.
Stacks and Queues. DCS – SWC 2 Stacks A stack is an abstract data structure, with some special properties: –Insertion and deletion is only allowed at.
GRAPH TRAVERSING BY PROF. UZAIR SALMAN
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Double-Ended Queues Chapter 5.
Infix to postfix conversion
Chapter 15 Lists Objectives
Stacks and Queues CMSC 202.
Stacks and Queues.
Wednesday, February 28, 2018 Announcements… For Today…
Abstract Data Types Stack, Queue Amortized analysis
'. \s\s I. '.. '... · \ \ \,, I.
Pointers and Linked Lists
Depth First Search—Backtracking
Stacks, Queues, and Deques
CSCI The UNIX System Shell History and Directory Stacks
Stacks and Queues.
Abstract Data Types Stack, Queue Amortized analysis
Abstract Data Types Stack, Queue Amortized analysis
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
' '· \ ·' ,,,,
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Queue Applications Lecture 31 Mon, Apr 9, 2007.
UNIT-II.
STL Библиотека стандартных шаблонов
Queue Applications Lecture 31 Tue, Apr 11, 2006.
C++ STL Stack, Queue, and Deque
CS210- Lecture 6 Jun 13, 2005 Announcements
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Abstract Data Types Stack, Queue Amortized analysis
Queues Linear list. One end is called front. Other end is called rear.
Types of Errors And Error Analysis.
Stack Implementations
Presentation transcript:

The Potential Method

Deque with stacks size=7 13 S1S1 S2S2 push(x,D): push(x,S 1 ) push(2,D)

Implementation with stacks size= S1S1 S2S2 push(x,D): push(x,S 1 ) push(2,D)

Pop size=8 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D)

Pop size=7 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D) pop(D)

Pop 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) pop(D)

Pop 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

Delete from Queue size=5 S1S1 S2S2 4 Pop size=4 S1S1 S2S2 4

The potential method

If then.

PUSH The same for POP without split

S1S1 S2S S1S1 S2S2 5 4 s=6 s/32s/3 POP that calls SPLIT