Using Queues: Coded Messages

Slides:



Advertisements
Similar presentations
Queues and Linked Lists
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.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
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.
1 Queues (Continued) Applications for a queue Linked queue implementation Array queue implementation Circular array queue implementation Reading L&C 3.
Topic 9 The Queue ADT.
CHAPTER 7 Queues.
5/4/20151 Queues Implementations. 5/4/20152 Outline Queues Basic operations Examples of useImplementations Array-based and linked list-based.
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.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
Chapter 14 Queues. Chapter Scope Queue processing Using queues to solve problems Various queue implementations Comparing queue implementations Java Foundations,
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queues.
Queues. … frontrear dequeueenqueue Message queues in an operating system There are times that programs need to communicate with each other.
Circular queue. Array-based Queue Use an array of size N in a circular fashion Three variables keep track of the front, rear, and size f index of the.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
Chapter 14 Queues. First a Review Queue processing Using queues to solve problems – Optimizing customer service simulation – Ceasar ciphers – Palindrome.
Chapter 7 Queues. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2 Chapter Objectives Examine queue processing Define a queue abstract.
COS 312 DAY 20 Tony Gauvin. Ch 1 -2 Agenda Questions? Capstone Progress reports over due Assignment 6 Posted – Due April 16 – Questions? Queues.
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
Lecture7: Queue Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Stacks And Queues Chapter 18.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 5: Queues Java Software Structures: Designing and Using Data.
Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.
Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only. FIFO.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
Queue. Avoid confusion Britain Italy 6 Applications of Queues Direct applications –Waiting lists, bureaucracy –Access to shared resources (e.g.,
Queue. The Queue ADT Insertions and deletions follow the first-in first-out scheme Insertions are at the rear of the queue and removals are at the front.
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.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Circular Queues Maitrayee Mukerji. Queues First In – First Out (FIFO) The first element to be inserted is the first one to be retrieved Insertion at one.
1 Data Structures and Algorithms Queue. 2 The Queue ADT Introduction to the Queue data structure Designing a Queue class using dynamic arrays Linked Queues.
The Queue ADT.
Data Structures Using C, 2e
Computing with C# and the .NET Framework
CS505 Data Structures and Algorithms
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.
Queues Chapter 4.
Queues Rem Collier Room A1.02
Queues Implementations 6/17/2018.
Csc 2720 Data structure Instructor: Zhuojun Duan
COS 312 DAY 21 Tony Gauvin.
Queues Queue Concept Queue Design Considerations
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Queue.
Queues Queues Queues.
Queues Chapter 4.
CSCE 3110 Data Structures & Algorithm Analysis
Chapter 5 Queues.
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/9/2018 6:32 PM Queues.
Stacks, Queues, and Deques
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Circular queue.
DATA STRUCTURE QUEUE.
Queue.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Computer Science 2 Hashing.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Queues Jyh-Shing Roger Jang (張智星)
Data Structures & Programming
Presentation transcript:

Using Queues: Coded Messages A repeating key is a sequence of integers that determine by how much each character in a message is shifted. Consider the repeating key 3 1 7 4 2 5 message: knowledge encoded message: a b c d e f g h i j k l m n o p q r s t u v w x y z 3 1 7 4 2 5 queue:

Using Queues: Coded Messages A repeating key is a sequence of integers that determine by how much each character in a message is shifted. Consider the repeating key 3 1 7 4 2 5 message: knowledge encoded message: n a b c d e f g h i j k l m n o p q r s t u v w x y z dequeued: 3 1 7 4 2 5 queue:

Using Queues: Coded Messages A repeating key is a sequence of integers that determine by how much each character in a message is shifted. Consider the repeating key 3 1 7 4 2 5 message: knowledge encoded message: n a b c d e f g h i j k l m n o p q r s t u v w x y z 1 7 4 2 5 3 queue:

Using Queues: Coded Messages A repeating key is a sequence of integers that determine by how much each character in a message is shifted. Consider the repeating key 3 1 7 4 2 5 message: knowledge encoded message: no a b c d e f g h i j k l m n o p q r s t u v w x y z dequeued: 1 7 4 2 5 3 queue:

Using Queues: Coded Messages A repeating key is a sequence of integers that determine by how much each character in a message is shifted. Consider the repeating key 3 1 7 4 2 5 message: knowledge encoded message: no a b c d e f g h i j k l m n o p q r s t u v w x y z 7 4 2 5 3 1 queue:

Using Queues: Coded Messages A repeating key is a sequence of integers that determine by how much each character in a message is shifted. Consider the repeating key 3 1 7 4 2 5 message: knowledge encoded message: novangjhl a b c d e f g h i j k l m n o p q r s t u v w x y z 4 2 5 3 1 7 queue:

Second Approach: Queue as a Circular Array Circular array is an array that conceptually loops around on itself 1 2 3 4 n-2 n-1 …

Circular Array 1 2 3 4 n-2 n-1 … 2 3 4 1 n-1 n-2 . . .

Circular Queue 2 cq front queue 1 2 3 4 5 6 7 8 9 10 9 rear count

Algorithm in pseudocode for the dequeue operation on a circular array representation of a queue Algorithm dequeue() { if queue is empty then ERROR result = queue[front] count = count – 1 queue[front] = null front = (front + 1) mod (size of array queue) return result } Where mod is the modulo operator (or modulus or remainder), denoted % in Java.

Example: full array 1 2 3 The array is now full 2 front queue cq 1 4 1 2 3 The array is now full 2 front queue cq 1 4 rear count

Example: full array If we add another element we need to expand the array 1 2 3 2 front queue cq 2 4 rear count

Example: full array If we add another element we need to expand the array 1 2 3 2 front queue cq 2 4 rear count 1 2 3 4 5 6 7

Example: full array But we cannot just copy the data to the same positions in the larger array 1 2 3 2 front queue cq 2 4 rear count 1 2 3 4 5 6 7

Example: full array But we cannot just copy the data to the same positions in the larger array 1 2 3 2 front queue cq 2 4 rear count 1 2 3 4 5 6 7 These locations should be in use

Example: full array We could build the new array, and copy the queue elements into contiguous locations beginning at location front: 1 2 3 4 5 6 7 2 front queue cq 2 4 rear count

Example: full array Or we could copy the queue elements in order to the beginning of the new array 1 2 3 4 5 6 7 front queue cq 4 4 rear count

Algorithm enqueue(element) { if queue is full then { // Expand the array q = new array of size 2 * size of queue copied = 0 // number of elements copied to the larger array i = 0 // index of next entry in array q j = front // index of next entry in array queue while copied < count do { // copy data to new array q[i] = queue[j] ++i j = (j + 1) mod size of queue ++ copied } rear = i – 1 // position of last element in the queue front = 0 queue = q rear = (rear + 1) mod size of queue queue[rear] = element ++count