Topic 16 Queues "FISH queue: n.

Slides:



Advertisements
Similar presentations
Queues and Linked Lists
Advertisements

Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Chapter 7 Queues. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine queue processing Define a queue abstract.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
TCSS 342, Winter 2005 Lecture Notes
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
Implementing and Using Stacks
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
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’
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Topic 16 Queues "FISH queue: n. [acronym, by analogy with FIFO (First In, First Out)] ‘First In, Still Here’. A joking way of pointing out that processing.
Queues CS 367 – Introduction to Data Structures. Queue A queue is a data structure that stores data in such a way that the last piece of data stored,
1 CS162: Introduction to Computer Science II Abstract Data Types.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Stacks and Queues. 2 Abstract Data Types (ADTs) abstract data type (ADT): A specification of a collection of data and the operations that can be performed.
Linked Data Structures
Building Java Programs
Elementary Data Structures
Review Array Array Elements Accessing array elements
Week 4 - Monday CS221.
Understanding Algorithms and Data Structures
QueueStack CS1020.
Week 4 - Friday CS221.
Linked List Stacks, Linked List Queues, Dequeues
CSE 116/504 – Intro. To Computer Science for Majors II
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Queues Queues Queues.
Building Java Programs
Topic 16 Queues "FISH queue: n.
Basic Data Types Queues
Topic 16 Queues Adapted from Mike Scott’s materials.
structures and their relationships." - Linus Torvalds
Queues.
Queue, Deque, and Priority Queue Implementations
Java Methods Stacks and Queues A & AB Object-Oriented Programming
Queues.
Queue.
Linked Lists: Implementation of Queue & Deque
Stacks and Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
List Data Structure.
CSC 143 Queues [Chapter 7].
Building Java Programs
Building Java Programs
Linked Lists [AJ 15].
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Stacks and Queues CLRS, Section 10.1.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
slides created by Marty Stepp
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
More Data Structures (Part 1)
Lecture 16 Stacks and Queues CSE /26/2018.
Lecture 16 Stacks and Queues CSE /26/2018.
structures and their relationships." - Linus Torvalds
Stacks and Queues.
CMPT 225 Lecture 8 – Queue.
Data Structures & Programming
Presentation transcript:

Topic 16 Queues "FISH queue: n. [acronym, by analogy with FIFO (First In, First Out)] ‘First In, Still Here’. A joking way of pointing out that processing of a particular sequence of events or requests has stopped dead. Also FISH mode and FISHnet; the latter may be applied to any network that is running really slowly or exhibiting extreme flakiness." -The Jargon File 4.4.7 CS 307 Fundamentals of Computer Science Queues

Queues In Britain people don’t “get in line” they “queue up”. Similar to Stacks Like a line In Britain people don’t “get in line” they “queue up”. CS 307 Fundamentals of Computer Science Queues

Queue Properties Queues are a first in first out data structure FIFO (or LILO, but that sounds a bit silly) Add items to the end of the queue Access and remove from the front Access to the element that has been in the structure the longest amount of time Used extensively in operating systems Queues of processes, I/O requests, and much more CS 307 Fundamentals of Computer Science Queues

Queues in Operating Systems On a computer with 1 CPU, but many processes how many processes can actually use the CPU at a time? One job of OS, schedule the processes for the CPU issues: fairness, responsiveness, progress CS 307 Fundamentals of Computer Science Queues

Queue operations add(Object item) Object get() Object remove() a.k.a. enqueue(Object item) Object get() a.k.a. Object front(), Object peek() Object remove() a.k.a. Object dequeue() boolean isEmpty() Specify in an interface, allow varied implementations CS 307 Fundamentals of Computer Science Queues

Queue interface, version 1 public interface Queue { //place item at back of this Queue enqueue(Object item); //access item at front of this queue //pre: !isEmpty() Object front(); //remove item at front of this queue //pre: !isEmpty() Object dequeue(); boolean isEmpty(); } CS 307 Fundamentals of Computer Science Queues

Implementing a Queue Given the internal storage container and choice for front and back of queue what are the Big O of the queue operations? ArrayList LinkedList LinkeList (Singly Linked) (Doubly Linked) enqueue front dequeue isEmpty CS 307 Fundamentals of Computer Science Queues

Attendance Question 1 If implementing a queue with a singly linked list with references to the first and last nodes (head and tail) which end of the list should be the front of the queue in order to have all queue operations O(1)? The front of the list should be the front of the queue The back of the list should be the front of the queue. C. D. E. I don’t know, but I am sure looking forward to taking 307 again some time. CS 307 Fundamentals of Computer Science Queues

Alternate Implementation How about implementing a Queue with a native array? Seems like a step backwards CS 307 Fundamentals of Computer Science Queues

Application of Queues Radix Sort radix is a synonym for base. base 10, base 2 Multi pass sorting algorithm that only looks at individual digits during each pass Use queues as buckets to store elements Create an array of 10 queues Starting with the least significant digit place value in queue that matches digit empty queues back into array repeat, moving to next least significant digit CS 307 Fundamentals of Computer Science Queues

Radix Sort in Action: 1s original values in array Look at ones place 113, 70, 86, 12, 93, 37, 40, 252, 7, 79, 12 Look at ones place Queues: 0 70, 40 5 1 6 86 2 12, 252, 12 7 37, 7 3 113, 93 8 4 9 9, 79 CS 307 Fundamentals of Computer Science Queues

Radix Sort in Action: 10s Empty queues in order from 0 to 9 back into array 70, 40, 12, 252, 12, 113, 93, 86, 37, 7, 9, 79 Now look at 10's place 70, 40, 12, 252, 12, 113, 93, 86, 37, 7, 9, 79 Queues: 0 7, 9 5 252 1 12, 12, 113 6 2 7 70, 79 3 37 8 86 4 40 9 93 CS 307 Fundamentals of Computer Science Queues

Radix Sort in Action: 100s Empty queues in order from 0 to 9 back into array 7, 9, 12, 12, 113, 37, 40, 252, 70, 79, 86, 93 Now look at 100's place __7, __9, _12, _12, 113, _37, _40, 252, _70, _79, _86, _93 Queues: 0 7, 9, _12, _12, _40, _70, _79, _86, _93 5 1 113 6 2 252 7 3 8 4 9 CS 307 Fundamentals of Computer Science Queues

Radix Sort in Action: Final Step Empty queues in order from 0 to 9 back into array 7, 9, 12, 12, 40, 70, 79, 86, 93, 113, 252 CS 307 Fundamentals of Computer Science Queues

Radix Sort Code public static void sort(int[] list){ ArrayList<Queue<Integer>> queues = new ArrayList<Queue<Integer>>(); for(int i = 0; i < 10; i++) queues.add( new LinkedList<Integer>() ); int passes = numDigits( list[0] ); int temp; for(int i = 1; i < list.length; i++){ temp = numDigits(list[i]); if( temp > passes ) passes = temp; } for(int i = 0; i < passes; i++){ for(int j = 0; j < list.length; j++){ queues.get(valueOfDigit(list[j], i)).add(list[j]); int pos = 0; for(Queue<Integer> q : queues){ while( !q.isEmpty()) list[pos++] = q.remove(); CS 307 Fundamentals of Computer Science Queues