CSC 212 – Data Structures Lecture 20: Deques. Question of the Day How did the clerk know that the man telling the following story is a fraud? I hope you.

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

1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
0 of 37 Stacks and Queues Lecture of 37 Abstract Data Types To use a method, need to know its essentials: signature and return type o additionally,
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Elementary Data Structures CS 110: Data Structures and Algorithms First Semester,
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Stacks.
Stacks, Queues & Deques CSC212.
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
Queues, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
Stacks, Queues, and Deques
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
Stacks and Linked Lists. Abstract Data Types (ADTs) An ADT is an abstraction of a data structure that specifies – Data stored – Operations on the data.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
CSC Programming for Science Lecture 16: Debugging.
Problem of the Day Bezout acquired 19 camels through his trading skill, “Of the collected camels,” it said in the late merchant’s will, “Exactly half go.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
Stacks And Queues Chapter 18.
Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
LECTURE 27: DEQUES CSC 212 – Data Structures. Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too! Stack & ADT Memory.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
CS 367 Introduction to Data Structures Lecture 5.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
Queue. Avoid confusion Britain Italy 6 Applications of Queues Direct applications –Waiting lists, bureaucracy –Access to shared resources (e.g.,
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
CH 5 : STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
1 Queues (Continued) Queue ADT Linked queue implementation Array queue implementation Circular array queue implementation Deque Reading L&C , 9.3.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Elementary Data Structures
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Double-Ended Queues Chapter 5.
Csc 2720 Data structure Instructor: Zhuojun Duan
Queues Queues Queues.
Priority Queue.
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues, Deques and Priority Queues
Queues 11/9/2018 6:32 PM Queues.
Queues, Deques and Priority Queues
Stacks, Queues, and Deques
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Queue.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Stacks, Queues, and Deques
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Copyright © Aiman Hanna All rights reserved
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks, Queues, and Deques
Queues.
Stacks and Linked Lists
CMPT 225 Lecture 8 – Queue.
Queues, Deques, and Priority Queues
Presentation transcript:

CSC 212 – Data Structures Lecture 20: Deques

Question of the Day How did the clerk know that the man telling the following story is a fraud? I hope you can help me. I'm an English Professor and I find myself in need of help. My wife and oldest daughter went shopping with my wallet which contained my cash and my credit cards and my identification and all that. My other daughter has taken ill in our hotel room. I must buy her some medication immediately, but I have no money. I have a check in my jacket pocket, but I, of course, have no identification. older

Debugging a Program Debug program when not working properly  Could be an error in the code  Program logic could be incorrect  Design may not allow certain features Better to find a bug as early as possible  Easiest to fix when still on paper  Understood best immediately after writing it This is NOT just a programming issue  Debugging is best when starting early

Starting the Program How to start a program 1. Determine what the problem is asking 2. Come up with a good set of tests cases Test cases crucial for working programs  After all, how else can you know it works?  Include a range of different possible inputs  For each input determine the correct output

Test Cases Begin with description of input and output  How else do you know where to start?  How else can you check if you are correct? Break up into different possible outcomes Example: rounding float to nearest int  Positive rounding up  Positive rounding down , 12.1,  Negative rounding down , ,  Negative rounding up , ,  Whole numbers -- 6, -4, 0

Begin to Develop Algorithm Much easier to start on paper  Easier to write, test, and fix Break problem into smaller steps  Each step need not be easy or obvious  Break test cases to test each step  Do not worry solving subproblems yet Use test cases to verify algorithm works  If it does not, go back and fix those problems

Solving Subproblems Solve subproblems separately  Do not worry about larger problem or issues  Can break up into even smaller subproblems  Worry about code only when it is obvious Solving problems in any part of life  Solving large problems is hard  Solving small problems is not

Stack Interface public interface Collection { public int size(); public boolean isEmpty(); } public interface Stack extends Collection { public E top() throws EmptyStackException; public E pop() throws EmptyStackException; public void push(E element); }

Queue Interface public interface Queue extends Collection { public E front() throws EmptyQueueException; public E dequeue() throws EmptyQueueException; public void enqueue(E element); }

Stacks vs. Queues Stacks access data using LIFO order  Last In-First Out  Good for the perpetually late Queues access data in FIFO order  First In-First Out  Resembles how we handle lines

Limitations of these ADTs Need to access both sides of Collection  Transplant waiting lists  Help center phone banks  My Grandpa playing cards Cannot be done with Stack  Can only insert at & access top Cannot be done with Queue  Can only add to end, get element from front

Deque ADT Pronounced “deck”  Avoids mistaking it for dequeue()  Stands for Double Ended QUEue Elements added & removed from front & rear Can be implemented with array or linked list  Really needs doubly-linked list Combines Stack and Queue ADT

Deque Interface public interface Deque extends Collection { public E getFirst() throws EmptyDequeException; public E getLast() throws EmptyDequeException; public E removeFirst() throws EmptyDequeException; public E removeLast() throws EmptyDequeException; public E addFirst(); public E addLast(); }

Your Turn Get back into groups and do activity

Before Next Lecture… Keep up with your reading! Start Week #9 Assignment Work on Programming Assignment #2