![Page 1: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/1.jpg)
ITEC200 Week06
Queues
![Page 2: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/2.jpg)
www.ics.mq.edu.au/ppdp 2
Learning Objectives – Week06Queues (Ch6)
Students can• Manage data using the queue Abstract Data Type and
the methods provided in it’s Java implementation (offer, remove, poll, peek and element)
• Compare and contrast implementations of the Queue interface (single-linked list, double-linked list, circular array) and make augmentations to them
• Analyse and augment a simulation of a physical system that uses Queues and random number generators
• Recognise appropriate circumstances to implement queues for data management and simulation purposes
![Page 3: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/3.jpg)
www.ics.mq.edu.au/ppdp 3
Queue Abstract Data Type
• Queue ADT is an organisation of data whereby insertion occurs at the tail and removal occurs at the head.
• Can visualize a queue as a line of customers waiting for service
• The next person to be served is the one who has waited the longest
• New elements are placed at the end of the line
![Page 4: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/4.jpg)
www.ics.mq.edu.au/ppdp 4
Applications of Queues
• Operating systems use queues to sequence tasks waiting for a scarce resource– Printer queue
– Tasks waiting for CPU
• Simulation of physical systems uses queues to simulate any ‘first-in first-out’ (FIFO) system– Supermarket checkouts
– Tollbooths
![Page 5: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/5.jpg)
www.ics.mq.edu.au/ppdp 5
Specification for a Queue Interface
![Page 6: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/6.jpg)
www.ics.mq.edu.au/ppdp 6
Class LinkedList Implements the Queue Interface
• The Java 5.0 LinkedList class implements the Queue interface: Queue<String> names = new LinkedList<String>();
creates a new Queue reference, names, that stores references to String objects
• The actual object referenced by names is type LinkedList<String>
• Because names is a type Queue<String> reference, you can apply only the Queue methods to it.
![Page 7: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/7.jpg)
www.ics.mq.edu.au/ppdp 7
Case Study: Maintaining a Queue of Customers
• Class MaintainQueue provides a GUI to perform operations on the queue
• Algorithms for GUI and for finding the position of a person in the queue are considered
![Page 8: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/8.jpg)
www.ics.mq.edu.au/ppdp 8
Using a Double-Linked List to Implement the Queue Interface
• Insertion and removal from either end of a double-linked list is O(1) so either end can be the front (or rear) of the queue
• Java designers decided to make the head of the linked list the front of the queue and the tail the rear of the queue
• Limitation: LinkedList object is used as a queue, it may be possible to apply other LinkedList methods in addition to the ones required by the Queue interface
![Page 9: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/9.jpg)
www.ics.mq.edu.au/ppdp 9
Using a Single-Linked List to Implement a Queue
• Can implement a queue using a single-linked list• Class ListQueue contains a collection of Node<E>
objects
![Page 10: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/10.jpg)
www.ics.mq.edu.au/ppdp 10
Implementing a Queue Using a Circular Array
• Time efficiency of using a single- or double-linked list to implement a queue is acceptable, however there are some space inefficiencies
• Implementing a Queue as a Circular Array overcomes space inefficiencies
![Page 11: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/11.jpg)
www.ics.mq.edu.au/ppdp 11
Implementing a Queue Using a Circular Array (continued)
![Page 12: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/12.jpg)
www.ics.mq.edu.au/ppdp 12
Comparing the Three Implementations
• All three implementations are comparable in terms of computation time
• Linked-list implementations require more storage because of the extra space required for the links– Each node for a single-linked list stores a total of two references
– Each node for a double-linked list would store a total of three references
• A circular array that is filled to capacity would require half the storage of a single-linked list to store the same number of elements
![Page 13: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/13.jpg)
www.ics.mq.edu.au/ppdp 13
Simulating Waiting Lines Using Queues
• Simulation is used to study the performance of a physical system by using a physical, mathematical, or computer model of the system
• Simulation allows designers of a new system to estimate the expected performance before building it
• Simulation can lead to changes in the design that will improve the expected performance of the new system
• Useful when the real system would be too expensive to build or too dangerous to experiment with after its construction
![Page 14: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/14.jpg)
www.ics.mq.edu.au/ppdp 14
Case Study: Simulating a Strategy for Serving Airline Passengers
![Page 15: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/15.jpg)
www.ics.mq.edu.au/ppdp 15
Simulate a Strategy for Serving Airline Passengers (continued)
![Page 16: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/16.jpg)
www.ics.mq.edu.au/ppdp 16
Simulate a Strategy for Serving Airline Passengers (continued)
![Page 17: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/17.jpg)
www.ics.mq.edu.au/ppdp 17
Simulating Waiting Lines Using Queues (continued)
![Page 18: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/18.jpg)
www.ics.mq.edu.au/ppdp 18
Simulating Waiting Lines Using Queues (continued)
![Page 19: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/19.jpg)
www.ics.mq.edu.au/ppdp 19
Simulating Waiting Lines Using Queues (continued)
![Page 20: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/20.jpg)
www.ics.mq.edu.au/ppdp 20
Simulating Waiting Lines Using Queues (continued)
![Page 21: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/21.jpg)
www.ics.mq.edu.au/ppdp 21
Simulating Waiting Lines Using Queues (continued)
![Page 22: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/22.jpg)
www.ics.mq.edu.au/ppdp 22
Simulating Waiting Lines Using Queues (continued)
![Page 23: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/23.jpg)
www.ics.mq.edu.au/ppdp 23
Where to from here…
• Work through Chapter 6 of the Koffman & Wolfgang Text
• Conceptual Questions and Practical Exercises• Submit all preliminary work• Be prompt for your online class
![Page 24: ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type](https://reader030.vdocuments.site/reader030/viewer/2022032800/56649d2b5503460f94a01577/html5/thumbnails/24.jpg)
www.ics.mq.edu.au/ppdp 24
Acknowledgements
These slides were based upon the Objects, Abstraction, Data Structures and Design using Java Version 5.0 Chapter 6 PowerPoint presentation
by Elliot B. Koffman and Paul A. T. Wolfgang