Definition: Data Structure that allows adding elements (enqueue) on one end and removal (dequeue) from the other end.

Similar documents
Data Structures and Algorithms V Otávio Braga

Chapter 3: Restricted Structures Page 1

Data Structures and Algorithms Stacks and Queues

DATA STRUCTURES USING C

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

Queues and Stacks. Atul Prakash Downey: Chapter 15 and 16

St S a t ck a ck nd Qu Q eue 1

Module 2 Stacks and Queues: Abstract Data Types

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

DATA STRUCTURE - QUEUE

Linked Lists Linked Lists, Queues, and Stacks

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Programming with Data Structures

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

7.1 Our Current Model

Data Structure [Question Bank]

Common Data Structures

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

STACKS,QUEUES, AND LINKED LISTS

Application of Stacks: Postfix Expressions Calculator (cont d.)

Algorithms and Data Structures

Analysis of a Search Algorithm

Stacks. Data Structures and Data Types. Collections

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Introduction to Stacks

Universidad Carlos III de Madrid

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structures UNIT III. Model Question Answer

10CS35: Data Structures Using C

DATA STRUCTURE - STACK

PES Institute of Technology-BSC QUESTION BANK

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

\Mankinds's progress is measured by the number of. Elementary data structures such as stacks, queues,

Data Structures and Algorithms

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

14 Stacks, Queues, And Linked Lists

CmpSci 187: Programming with Data Structures Spring 2015

Data Structures and Data Manipulation

Introduction to Data Structures and Algorithms

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Sequential Data Structures

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LESSON PLAN

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

Collaboration policy. Where to get help (but no code in ) Office hours Lab TAs in Friend 008/009 Bounce ideas (but not code) off classmates

Stacks and queues. Algorithms and Data Structures, Fall Rasmus Pagh. Based on slides by Kevin Wayne, Princeton

EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE)

Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Cpt S 223. School of EECS, WSU

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Data Structures/Stacks and Queues

COMPUTER SCIENCE. Paper 1 (THEORY)

Java Software Structures

KWIC Exercise. 6/18/ , Spencer Rugaber 1

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: Data Structures

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Towards Relaxing STM. Christoph M. Kirsch, Michael Lippautz! University of Salzburg. Euro-TM Workshop, April 2014

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

3 Abstract Data Types and Search

Data Structures. Level 6 C Module Descriptor

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Administrative Issues

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

HW3: Programming with stacks

Lecture Notes on Stacks & Queues

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Queue Definition. Queues. Queue. Slides. 11. Queues. 11. Queues

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

7. Object-Oriented Programming

Data Structures in the Java API

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Abstract Data Types. Chapter 2

Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

Algorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser

Computer Programming using C

List, Stack and Queue. Tom Chao Zhou CSC2100B Data Structures Tutorial 3

Lab Manual. Data Structures (Pr): COT-213 Data Structures (P): IT-215

Algorithms and Data Structures Written Exam Proposed SOLUTION

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

Evolving Data Structures with Genetic Programming

Big O and Limits Abstract Data Types Data Structure Grand Tour.

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Shortest Path Algorithms

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

Basic Data Structures and Algorithms

Transcription:

CS1706 Intro to Object Oriented Dev II - Fall 04 Announcements Week 08 Homework 3 quiz due Monday Program 2 due 11/01 Material Discussion of Project 2 Implementation of stacks Queues

Queue Definition: Data Structure that allows adding elements (enqueue) on one end and removal (dequeue) from the other end. Dynamic FIFO Storage Structure Size and Contents can change during execution First in First Out Elements are inserted (enqueue) into the rear and retrieved (dequeue) from front.

View of a queue Operations enqueue - add element at end dequeue - remove element from front first - examine first element (similiar to stack.peek()) isempty size

Radix Sort Algorithm uses an array of queue Divide numbers into 10 different queues by looking at each digit at a time 1st loop: use the single digits and place 0s on queue 0, 1s on queue 1, etc. 2nd loop: take numbers in order of queue 0, queue 1, etc. and organize them by tens digit repeat for all positions

Radix sort One of few sorting algorithms not based on comparision of keys Code is in the book (L& C: Chap. 7) What is Big O of this algorithm? What are the drawbacks?

Infix to Postfix Algorithm uses a string with an infix expression and produces a corresponding postfix expression stored in a queue. Internally, the algorithm uses a queue and a stack to store its results. The queue is returned and the stack is discarded after completion. Starts with an empty queue, (the postfix queue), uses an operator stack, & returns the queue Operators have precendence which must be considered, any number of parenthesis are possible

Infix to Postfix: Steps Parse the input infix expression: if you find an operand, add it to the postfix queue if you find an operator, pop off the stack all operators (not parens) that have equal or higher precedence and add them to the postfix queue. Then push the operator found in the input infix expression onto the stack. if you find a left parenthesis, push it onto the stack if you find a right parenthesis, pop operators from the stack and add them to the queue until you find the matching left parenthesis, which you can ignore When you find the end of the infix expression, copy all remaining operators in the stack to the queue Return the queue

Implementations of Queues Array Implementation similar to queues need index to head and index to tail on insert, shift all up Add to end, remove from front What is the inefficiency here? How can it be solved? dequeue [0] [rear] [n] enqueue

What if... What if we did not shifting? [0] [rear] [n] Add to the [rear] increment rear Remove from the [front] increment front dequeue [front] enqueue [rear] [n] dequeue enqueue

Circular Array Circular Array Queue Code operations to force array indicies to wrap-around front = (front + 1) % MAXQUE ; rear = (rear + 1) % MAXQUE ; MAXQUE-1 0 1 front front and rear indicies delimit the bounds of the queue contents Enqueue: Move the rear index 1 position clockwise & write the element in that position. Dequeue: One-element Queue Queue Return element at front and move front one position clockwise Count (queue size) is stored and maintained or boolean full status flag maintained. queue rear front rear

Circular Array Queue Special cases Empty or Full Queue? Assume queue has 1 element. rear front Dequeue the element. Where are the indicies? Fill up the queue. Where are the indicies? Solution design implementation to ensure that different states of the queue are represented distinctly eliminates need to maintain a queue size count.

Circular Array Queue Solution Front refers to the position preceding actual front element full queue: contains (max - 1) elements. front Tradeoff: one memory location saves processing (maintaining queue size count) rear MAXQUE-1 0 1 Distinct States Full Queue: (que.rear + 1) % MAXQUE == que.front Empty Queue: (que.rear == que.front ) One-element Queue: (que.front + 1) % MAXQUE == que.rear