09-queues.pdf

# 09-queues.pdf - Felix Xiaozhu Lin Lecture 8 Queues Deques...

• 44

This preview shows page 1 - 13 out of 44 pages.

Felix Xiaozhu Lin Lecture 8: Queues, Deques, Priority Queues Textbook Reading: Chapter 4 (pp. 153-161), Chapter 9 (pp. 383-392) Slides Courtesy: Prof. Vijay Raghunathan

Subscribe to view the full document.

Lecture 09: Overview Definition of queue ADT for queue Implementation of queues Deques Priority queues Reference pages 153-161, 383-392 2 ECE368: Data Structures
Lecture 09: Queue Def: An ordered collection of items where items are inserted at the end and are removed from the front First-In, First-Out (FIFO) Contrast with Stacks (LIFO) Applications: Waiting lines (printer queue) Buffers (input/output buffers) Event queues 3 ECE368: Data Structures

Subscribe to view the full document.

Lecture 09: Primitive operators How to use the queue (access the data) Three primitives: Empty: is queue empty? Remove item from the front Insert item at the end (rear) Check for exception conditions (similar to stacks) Underflow: violated pre-conditions Overflow: failed insert 4 ECE368: Data Structures
Lecture 09: Queue as an Abstract Data Type ADT typedef <<eltype>> QUEUE boolean empty (QUEUE Q) post-condition: empty == (len(Q) == 0); eltype remove (QUEUE Q) pre-condition: empty(Q) == FALSE; post-condition: remove == first(Q’); Q == sub(Q’, 1, len(Q’) – 1); insert (QUEUE Q, eltype i) post-condition: Q == Q’ + <i>; 5 ECE368: Data Structures

Subscribe to view the full document.

Lecture 09: Queue implementation Use resizable arrays malloc(), free(), realloc() Size and Minimum_Size fields Other fields Rear - array index for end of queue Front - array index for front of queue Want to have O(1) time complexity for primitive operators i.e., independent of the number of items in the queue 6 ECE368: Data Structures