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.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Queues and Linked Lists
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Data Structure HKOI training /4/2010 So Pak Yeung.
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.
Queue Definition Ordered list with property: –All insertions take place at one end (tail) –All deletions take place at other end (head) Queue: Q = (a 0,
Queues. Queue Definition Ordered list with property: All insertions take place at one end (tail) All insertions take place at one end (tail) All deletions.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Data Structures and Algorithms (60-254)
Queue & List Data Structures & Algorithm Abstract Data Types (ADTs) ADT is a mathematically specified entity that defines a set of its instances,
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.
Introduction to C Programming CE Lecture 12 Circular Queue and Priority Queue Data Structures.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
1 CS 201 Dynamic Data Structures (2) Debzani Deb.
Lists: array implementation list_size = 5 lst Obj 1Obj 2Obj 3Obj 4Obj 5.
The Potential Method. Deque with stacks size=7 13 S1S1 S2S2 push(x,D): push(x,S 1 ) push(2,D)
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
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.
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.
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CISC Data Structures Ben Perry University of Delaware Summer 2011.
Introduction to Data Structures Fall 2008 Dr. David A. Gaitros
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Chapter 16 Stacks & Queues. Objective In this chapter we will learn:  Stacks  Queues  Different implementations (arrays and linked list) of both 
A Introduction to Computing II Lecture 6: Lists, Stacks, and Queues Fall Session 2000.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
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.
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
Subject Name : Data Structure Using C Title : Linked Lists
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Queues. Like Stacks, Queues are a special type of List for storing collections of entities. Stacks are Lists where insertions (pushes) and deletions (pops)
Recitation 7 Collections. Array List and Linked List Array List and Linked List are implementations of the same interface: List. As a result, they have.
Linear Data Structures
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Queue, Deque, and Priority Queue Implementations Chapter 23.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
Algorithms and Data Structures Lecture VI
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
CISC220 Spring 2010 James Atlas Lecture 10: Queues.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Stack, Queues, and Priority Queues: Linked List Based
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Prefix notation in action
Data Structures Using C, 2e
Queues.
Week 4 - Monday CS221.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
Linked List Stacks, Linked List Queues, Dequeues
Chapter 15 Lists Objectives
Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.
Objectives In this lesson, you will learn to: Define stacks
Stacks and Queues CMSC 202.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Pointers and Linked Lists
Queues A first-in, first-out or FIFO data structure.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
CS210- Lecture 6 Jun 13, 2005 Announcements
Presentation transcript:

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 o Lynbrook has 3 finalists this year! o Johnny Ho o Steven Hao o Jimmy Zeng o That's probably more than any other school this year Officer elections o Check your for the application/instructions later today Stanford ProCo (5/19) registration o KR9EpyErNRlwnbfrq4jmYiM/viewform KR9EpyErNRlwnbfrq4jmYiM/viewform

Stacks and Queues Two Operations: Push and Pop o Push: add an element to your list o Pop: remove an element from your list Stack: Last in, first out o Example o Push 1, Push 5, Push 3, Pop [3] o Push 4, Pop [4] o Pop [5] Queue: First in, first out o Example o Push 1, Push 5, Push 3, Pop[1] o Push 4, Pop[5] o Pop[3]

Singly Linked Lists A data structure that can implement a stack or a queue Supports insertions and deletions at any known location in constant time o Supports pushing to the front, pushing to the back, popping from the front Store a head node and a tail node o Each node has a pointer to the next node o Ex. Push to the front: Make a new node, put it before the head, make it the new head.

Doubly Linked List Like a linked list but supports popping from the back too Stores almost the same thing as a linked list o Each node stores a "forward" pointer to the next node and a "reverse" pointer to the previous node o Ex. Pop from the back: Delete the tail, use the previous node as the new tail

Deque A doubly linked list can implement a deque very easily Deque can push/pop from front or back Useful for job scheduling applications o Threads operate on jobs starting from the front-end of queues o Threads can move jobs from one back-end of a queue to another

Better deque Implementation Circular buffer An array that wraps around the back to the front Store a head and tail in addition to the array This supports: o Constant time pop/push from front/back o Constant time random access

POTW Implement a queue with two stacks. Your program should support the queue operations push(x) and pop() using only two stacks. Sample input: push 5 push 6 push 2 pop push 4 pop push 1 pop Sample output: Constraints: N is the number of instructions (push and pop). 1<=N<=1000: 10 pts 1<=N<=500,000: 15 pts