Announcements. mp3.1 extra credit due tomorrow lab quacks due Saturday night (6/29) mp3 due Monday (7/1)

Similar documents
lecture14: Tree Traversals

lecture09: Linked Lists

lecture27: Graph Traversals

CS24 Week 4 Lecture 2

lecture24: Disjoint Sets

lecture23: Hash Tables

Memory, Arrays, and Parameters

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

lecture04: Constructors and Destructors

An Introduction to Queues With Examples in C++

All the above operations should be preferably implemented in O(1) time. End of the Queue. Front of the Queue. End Enqueue

CS 225. Nov. 13 Introduction to Graphs. Data Structures. Wade Fagen-Ulmschneider

Queue ADT. January 31, 2018 Cinda Heeren / Geoffrey Tien 1

Containers: Queue and List. Jordi Cortadella and Jordi Petit Department of Computer Science

ITI Introduction to Computing II

Stack and Queue. Stack:

lecture05: The Big Three

Object Oriented Programming COP3330 / CGS5409

lecture17: AVL Trees

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1

Lecture 2: Implementing ADTs

CS302 - Data Structures using C++

CS 225. April 6 Disjoint Sets Implementation. Data Structures. Wade Fagen-Ulmschneider

CS S-04 Stacks and Queues 1. An Abstract Data Type is a definition of a type based on the operations that can be performed on it.

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

Data Structures and Algorithms

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF.


COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

csci 210: Data Structures Stacks and Queues

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

Lecture 2: Stacks and Queues

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1

STACKS AND QUEUES. Problem Solving with Computers-II

CS 106B Lecture 5: Stacks and Queues

UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering EXAM November 2016

Programming Abstractions

Linked Lists and Abstract Data Structures A brief comparison

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Trees. Carlos Moreno uwaterloo.ca EIT

lecture29: Shortest Path Algorithms

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Largest Online Community of VU Students

Tuesday Extra this week; candidates for tenure-track position Refreshments 4:00 pm in CS Commons; Talk 4:15 pm in 3821 Nicole Eikmeier, Purdue

Data Structure Advanced

Extra Credit: write mystrlen1 as a single function without the second parameter int mystrlen2(char* str)

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

CMPT 225. Lecture 9 Stack

CS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list.

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

CS 225. April 9 Graphs Intro. Data Structures. Wade Fagen-Ulmschneider

CS 216 Exam 1 Fall SOLUTION

== isn t always equal?

Programming. Lists, Stacks, Queues

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures

EEE2020 Data Structures and Algorithms Abstract Data Types: Stacks and Queues

CSE 332: Data Structures. Spring 2016 Richard Anderson Lecture 1

Standard ADTs. Lecture 19 CS2110 Summer 2009

Data Structures -- Introduction

Abstract Data Types 1

ADTs Stack and Queue. Outline

Lecture 9 Stacks & Queues

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Ch. 18: ADTs: Stacks and Queues. Abstract Data Type

PA3 Design Specification

Queues 4/11/18. Many of these slides based on ones by Cynthia Lee

Data Structures and Algorithms for Engineers

Chapter 9 STACK, QUEUE

Name CPTR246 Spring '17 (100 total points) Exam 3

Stacks and Queues. David Greenstein Monta Vista

Postfix (and prefix) notation

CS350 - Exam 1 (100 Points)

ADTs: Stacks and Queues

Queues and Unit Testing

8. Fundamental Data Structures

Lecture 4 Stack and Queue

lecture30: Beyond CS 225

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Abstract Data Types. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Lecture 9 Notes Stacks & Queues

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

12 Abstract Data Types

CMSC 341. Deques, Stacks and Queues 9/22/04 1

COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008

Abstract Data Types 1

Stacks and Queues. CSE 373 Data Structures Lecture 6

Programming Abstractions

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Lecture 9 Stacks & Queues

Transcription:

lecture12: Largely based on slides by Cinda Heeren CS 225 UIUC 27th June, 2013

Announcements mp3.1 extra credit due tomorrow lab quacks due Saturday night (6/29) mp3 due Monday (7/1) Source: http://i.dailymail.co.uk/i/pix/2010/08/04/article-1300471-0ab0a1d2000005dc-451 468x286.jpg

A Queue is a First-In, First-Out (FIFO) or Last-In, Last Out (LILO) structure. An analogy is a line of people waiting for an event. ADT functions include: 1 enqueue 2 dequeue 3 peek 4 size 5 empty

What use is a Queue? CPU and disk scheduling CS 241 (systems) Process communication (as a buffer) CS 241 (systems) Doing traversals (just like Stacks!) mp4, lab graphs, possibly mp7 Parsing CS 421 (compilers), CS 498jhm (natural language processing) Letting people into rides at an amusement park (how?)

What choices do we have? /** @file queue.h */ class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: // what should go in here? };

Linked list or array? /** @file queue.h */ class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: size_t _size; size_t _capacity; T* _data; }; /** @file queue.h */ class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: // Node class... Node* head; size_t _size; };

Wait, we made these already... /** @file queue.h */ #include "vector.h" class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: Vector<T> _array; }; /** @file queue.h */ #include "list.h" class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: List<T> _list; };

Does any of this seem familiar yet? Is anyone having déjà vu? Stacks and are opposites: FIFO/LILO vs FILO/LIFO. They are each other s archnemesis.

The array implementation /** @file stack.cpp */ /** @file queue.h */ #include "vector.h" class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: Vector<T> _array; }; Queue<T>::Queue(): _array(vector<t>()); void Queue<T>::enqueue(const T & elem) } T Queue<T>::dequeue() }

The linked list implementation /** @file stack.cpp */ /** @file queue.h */ #include "list.h" class Queue public: Queue(); // + big 3 void enqueue(const T & elem); T dequeue(); T peek() const; size_t size() const; bool empty() const; private: List<T> _list; }; Queue<T>::Queue(): _list(list<t>()); void Queue<T>::enqueue(const T & elem) } T Queue<T>::dequeue() }

Linked list intricacies (again!) When implementing a Queue with a linked list, does it matter where the front of the Queue is (head or tail)? Does it matter if the linked list is a SLL or a DLL? We are concerned with an efficient running time!

Your favorite For linked lists, assume the front of the queue is the head of the list and the back of the queue is the tail of the list. Function Array SLL DLL enqueue dequeue peek

Your favorite

Parting thoughts Again, consider the alternative implementation of a Queue with a (singly/doubly)-linked list: the front is the tail and the back is the head Can you think of any other implementations for a Queue besides linked lists and arrays? A circularly linked list with only a head pointer Two Stacks (mp4.1!) Can you make a Stack with two?