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

Size: px
Start display at page:

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

Transcription

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

2 Announcements mp3.1 extra credit due tomorrow lab quacks due Saturday night (6/29) mp3 due Monday (7/1) Source: 468x286.jpg

3 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

4 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?)

5 What choices do we have? 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? };

6 Linked list or array? 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; }; 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; };

7 Wait, we made these already... 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.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; };

8 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.

9 The array implementation stack.cpp */ 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() }

10 The linked list implementation stack.cpp */ 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() }

11 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!

12 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

13 Your favorite

14 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?

lecture14: Tree Traversals

lecture14: Tree Traversals lecture14: Tree Largely based on slides by Cinda Heeren CS 225 UIUC 2nd July, 2013 Announcements lab trees due Saturday night (7/6) Reminder: no class 7/4 mp4.1 extra credit due Friday night (7/5) Source:

More information

lecture09: Linked Lists

lecture09: Linked Lists lecture09: Largely based on slides by Cinda Heeren CS 225 UIUC 24th June, 2013 Announcements mp2 due tonight mt1 tomorrow night! mt1 review instead of lab tomorrow morning mp3 released tonight, mp3.1 extra

More information

lecture27: Graph Traversals

lecture27: Graph Traversals lecture27: Largely based on slides by Cinda Heeren CS 225 UIUC 25th July, 2013 Announcements mp7.1 extra credit due tomorrow night (7/26) Code challenge tomorrow night (7/26) at 6pm in 0224 lab hash due

More information

CS24 Week 4 Lecture 2

CS24 Week 4 Lecture 2 CS24 Week 4 Lecture 2 Kyle Dewey Overview Linked Lists Stacks Queues Linked Lists Linked Lists Idea: have each chunk (called a node) keep track of both a list element and another chunk Need to keep track

More information

lecture24: Disjoint Sets

lecture24: Disjoint Sets lecture24: Largely based on slides by Cinda Heeren CS 225 UIUC 22nd July, 2013 Announcements mp6 due tonight mp7 out soon! mt3 tomorrow night (7/23) Optional review instead of lab tomorrow Code Challenge

More information

lecture23: Hash Tables

lecture23: Hash Tables lecture23: Largely based on slides by Cinda Heeren CS 225 UIUC 18th July, 2013 Announcements mp6.1 extra credit due tomorrow tonight (7/19) lab avl due tonight mp6 due Monday (7/22) Hash tables A hash

More information

Memory, Arrays, and Parameters

Memory, Arrays, and Parameters lecture02: Largely based on slides by Cinda Heeren CS 225 UIUC 11th June, 2013 Announcements hw0 due tomorrow night (6/12) Linux tutorial tonight in the lab mp1 released tomorrow night (due Monday, 6/17)

More information

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

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let

More information

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

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10 Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()

More information

lecture04: Constructors and Destructors

lecture04: Constructors and Destructors lecture04: Largely based on slides by Cinda Heeren CS 225 UIUC 13th June, 2013 Announcements lab debug due Saturday night (6/15) mp1 due Monday night (6/17) Warmup: what happens? /** @file main.cpp */

More information

An Introduction to Queues With Examples in C++

An Introduction to Queues With Examples in C++ An Introduction to Queues With Examples in C++ Prof. David Bernstein James Madison University Computer Science Department bernstdh@jmu.edu Motivation Queues are very straightforward but are slightly more

More information

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

All the above operations should be preferably implemented in O(1) time. End of the Queue. Front of the Queue. End Enqueue Module 4: Queue ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Queue ADT Features (Logical View) A List that

More information

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

CS 225. Nov. 13 Introduction to Graphs. Data Structures. Wade Fagen-Ulmschneider CS 225 Data Structures Nov. 13 Introduction to Graphs Wade Fagen-Ulmschneider UpTree 10 9 11 1 7 2 8 3 4 5 6 Disjoint Sets Find 1 2 3 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 int DisjointSets::find(int

More information

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

Queue ADT. January 31, 2018 Cinda Heeren / Geoffrey Tien 1 Queue ADT Cinda Heeren / Geoffrey Tien 1 PA1 testing Your code must compile with our private test file Any non-compiling submissions will receive zero Note that only functions that are called will be compiled

More information

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

Containers: Queue and List. Jordi Cortadella and Jordi Petit Department of Computer Science Containers: Queue and List Jordi Cortadella and Jordi Petit Department of Computer Science Queue A container in which insertion is done at one end (the tail) and deletion is done at the other end (the

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Queues ArrayQueue Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 10, 2014 Abstract These lecture notes are meant to be looked

More information

Stack and Queue. Stack:

Stack and Queue. Stack: Stack and Queue Stack: Abstract Data Type A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle. In the pushdown stacks only two operations

More information

lecture05: The Big Three

lecture05: The Big Three lecture05: Largely based on slides by Cinda Heeren CS 225 UIUC 17th June, 2013 Announcements mp1 due tonight at 11pm mp2 released tonight Significantly longer than mp1! Make sure to start early and use

More information

Object Oriented Programming COP3330 / CGS5409

Object Oriented Programming COP3330 / CGS5409 Object Oriented Programming COP3330 / CGS5409 Intro to Data Structures Vectors Linked Lists Queues Stacks C++ has some built-in methods of storing compound data in useful ways, like arrays and structs.

More information

lecture17: AVL Trees

lecture17: AVL Trees lecture17: Largely based on slides by Cinda Heeren CS 225 UIUC 9th July, 2013 Announcements mt2 tonight! mp5.1 extra credit due Friday (7/12) An interesting tree Can you make a BST that looks like a zig

More information

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

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1 Queues ADT description Implementations Cinda Heeren / Geoffrey Tien 1 Queues Assume that we want to store data for a print queue for a student printer Student ID Time File name The printer is to be assigned

More information

Lecture 2: Implementing ADTs

Lecture 2: Implementing ADTs Lecture 2: Implementing ADTs Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Discuss with your neighbors! From last lecture: - What is an ADT? - What is a data structure? From CSE

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Queues and Priority Queues Kostas Alexis Implementations of the ADT Queue Like stacks, queues can have Array-based or Link-based implementation Can also use implementation

More information

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

CS 225. April 6 Disjoint Sets Implementation. Data Structures. Wade Fagen-Ulmschneider CS 225 Data Structures April 6 Disjoint Sets Implementation Wade Fagen-Ulmschneider Disjoint Sets 2 5 9 7 0 1 4 8 3 6 5 7 4 3 9 2 0 8 6 1 0 4 1 2 3 4 5 6 7 8 5-1 -1-1 3-1 8 9 4 5 Disjoint Sets Find 1 2

More information

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.

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. CS245-2017S-04 Stacks and Queues 1 04-0: Abstract Data Types An Abstract Data Type is a definition of a type based on the operations that can be performed on it. An ADT is an interface Data in an ADT cannot

More information

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

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11. Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-04 Stacks and Queues David Galles Department of Computer Science University of San Francisco 04-0: Abstract Data Types An Abstract Data Type is a definition of

More information

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

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists Marzieh Ahmadzadeh University of Toronto Scarborough Administrative Detail All practicals are up on course website. Term test # 1 and #2 schedule

More information

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

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF. 15-122 Assignment 3 Page 1 of 12 15-122 : Principles of Imperative Computation Fall 2012 Assignment 3 (Theory Part) Due: Thursday, October 4 at the beginning of lecture. Name: Andrew ID: Recitation: The

More information

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

More information

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

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor COSC160: Data Structures: Lists and Queues Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Queues I. FIFO Queues I. Usage II. Implementations II. LIFO Queues (Stacks) I. Usage II. Implementations

More information

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

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.

More information

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

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013 Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every

More information

csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks

More information

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

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013 Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every

More information

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)

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) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

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

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very

More information

Lecture 2: Stacks and Queues

Lecture 2: Stacks and Queues Lecture 2: Stacks and Queues CSE 373: Data Structures and Algorithms CSE 373 19 WI - KASEY CHAMPION 1 Warm Up 1. Grab a worksheet 2. Introduce yourself to your neighbors J 3. Discuss the answers 4. Log

More information

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

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1 CMSC 341 Linked Lists, Stacks and Queues CMSC 341 Lists, Stacks &Queues 1 Goal of the Lecture To complete iterator implementation for ArrayList Briefly talk about implementing a LinkedList Introduce special

More information

STACKS AND QUEUES. Problem Solving with Computers-II

STACKS AND QUEUES. Problem Solving with Computers-II STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()

More information

CS 106B Lecture 5: Stacks and Queues

CS 106B Lecture 5: Stacks and Queues CS 106B Lecture 5: Stacks and Queues Monday, July 3, 2017 Programming Abstractions Summer 2017 Stanford University Computer Science Department Lecturer: Chris Gregg reading: Programming Abstractions in

More information

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

UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering EXAM November 2016 UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering 16.322 EXAM 2 14 November 2016 Problem Weight Score 1 30 % 2 36 % 3 32 % Bonus 2 % TOTAL 100 % INSTRUCTIONS You may

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Today s Topics ADTs Stack Example: Reverse-Polish Notation calculator Queue Example: Mouse Events Stacks New ADT: Stack stack.h template

More information

Linked Lists and Abstract Data Structures A brief comparison

Linked Lists and Abstract Data Structures A brief comparison Linked Lists and Abstract Data A brief comparison 24 March 2011 Outline 1 2 3 4 Data Data structures are a key idea in programming It s just as important how you store the data as it is what you do to

More information

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

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures 10/1/17 Abstract vs concrete data structures 2 Abstract data structures are interfaces they specify only interface (method names and specs) not implementation (method bodies, fields, ) HEAPS AND PRIORITY

More information

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

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department Abstract Data Structures IB Computer Science Content developed by Dartford Grammar School Computer Science Department HL Topics 1-7, D1-4 1: System design 2: Computer Organisation 3: Networks 4: Computational

More information

Trees. Carlos Moreno uwaterloo.ca EIT https://ece.uwaterloo.ca/~cmoreno/ece250

Trees. Carlos Moreno uwaterloo.ca EIT https://ece.uwaterloo.ca/~cmoreno/ece250 Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Today's class: We'll discuss one possible implementation for trees (the general type of trees) We'll look at tree

More information

lecture29: Shortest Path Algorithms

lecture29: Shortest Path Algorithms lecture29: Shortest Path Algorithms Largely based on slides by Cinda Heeren CS 225 UIUC 30th July, 2013 Outline 1 Announcements 2 3 4 Announcements lab graphs due Thursday, 8/1 final exam this Friday (8/2),

More information

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

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade Final Exam Review Final Exam Mon, May 5, 2:00PM to 4:30PM CS 2308 Spring 2014 Jill Seaman Closed book, closed notes, clean desk Comprehensive (covers entire course) 30% of your final grade I recommend

More information

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

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work. It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: Complete the mock final in 170 minutes. Work on your own. Keep your notes and textbook closed. Attempt every question.

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com WWW.VUTUBE.EDU.PK http://forum.vupages.com Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

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

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 Announcements Office Hours this week: normal Monday-Friday: 2:30 4:00 Attendance at last Friday's class embarrassing! Extra credit available for feedback from those here for full class Feedback from those

More information

Data Structure Advanced

Data Structure Advanced Data Structure Advanced 1. Is it possible to find a loop in a Linked list? a. Possilbe at O(n) b. Not possible c. Possible at O(n^2) only d. Depends on the position of loop Solution: a. Possible at O(n)

More information

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

Extra Credit: write mystrlen1 as a single function without the second parameter int mystrlen2(char* str) CPSC 122 Study Guide 3: Final Examination The final examination will consist of three parts: Part 1 covers mostly C++. For this, see study guides 1 and 2, exams 1 and 2, and part of exam 3, and quizzes

More information

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 1 Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:

More information

CMPT 225. Lecture 9 Stack

CMPT 225. Lecture 9 Stack CMPT 225 Lecture 9 Stack 1 Last Lecture We did an activity about Stack 2 Learning Outcomes 3 At the end of this lecture (and the activity), a student will be able to: Describe Stack Define public interface

More information

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

CS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux CS 231 Data Structures and Algorithms Fall 2018 DDL & Queue Lecture 20 October 22, 2018 Prof. Zadia Codabux 1 Agenda Mid Semester Analysis Doubly Linked List Queue 2 Administrative None 3 Doubly Linked

More information

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

CSE 373 Data Structures and Algorithms. Lecture 2: Queues CSE 373 Data Structures and Algorithms Lecture 2: Queues Queue ADT queue: A list with the restriction that insertions are done at one end and deletions are done at the other First-In, First-Out ("FIFO

More information

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

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

More information

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

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology Lecture 7: Data Structures 1 Introduction: dynamic array Conventional array in C has fix number of elements Dynamic array is array with variable number of elements: actually a pointer and a variable indicating

More information

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

CS 225. April 9 Graphs Intro. Data Structures. Wade Fagen-Ulmschneider CS 225 Data Structures April 9 Graphs Intro Wade Fagen-Ulmschneider Disjoint Sets Analysis The iterated log function: The number of times you can take a log of a number. log*(n) = 0, n 1 1 + log*(log(n)),

More information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

More information

== isn t always equal?

== isn t always equal? == isn t always equal? In Java, == does the expected for primitives. int a = 26; int b = 26; // a == b is true int a = 13; int b = 26; // a == b is false Comparing two references checks if they are pointing

More information

Programming. Lists, Stacks, Queues

Programming. Lists, Stacks, Queues Programming Lists, Stacks, Queues Summary Linked lists Create and insert elements Iterate over all elements of the list Remove elements Doubly Linked Lists Circular Linked Lists Stacks Operations and implementation

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2014 7-10p, Tuesday, April 8 Name: NetID: Lab Section

More information

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

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures Announcements A due TOMORROW. Late deadline is Sunday. A5 released. Due next Thursday. Deadline for Prelim 1 regrade requests is tomorrow. Remember to complete your TA evaluations by tonight. HEAPS & PRIORITY

More information

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

EEE2020 Data Structures and Algorithms Abstract Data Types: Stacks and Queues EEE2020 Data Structures and Algorithms Abstract Data Types: Stacks and Queues W. Jinho Song School of Electrical & Electronic Engineering Yonsei University 1 Textbook Chapter and Objectives Textbook "Data

More information

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

CSE 332: Data Structures. Spring 2016 Richard Anderson Lecture 1 CSE 332: Data Structures Spring 2016 Richard Anderson Lecture 1 CSE 332 Team Instructors: Richard Anderson anderson at cs TAs: Hunter Zahn, Andrew Li hzahn93 at cs lia4 at cs 2 Today s Outline Introductions

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

More information

Data Structures -- Introduction

Data Structures -- Introduction Data Structures -- Introduction Let s explore some advanced techniques for and managing information Chapter 16 focuses on: dynamic structures Abstract Data Types (ADTs) linked lists queues stacks 1 Static

More information

Abstract Data Types 1

Abstract Data Types 1 Abstract Data Types 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues 2 Abstract Data Types (ADTs) ADT is a set of objects together with a set of operations. Abstract in that implementation of operations

More information

ADTs Stack and Queue. Outline

ADTs Stack and Queue. Outline Chapter 5 ADTs Stack and Queue Fall 2017 Yanjun Li CS2200 1 Outline Stack Array-based Implementation Linked Implementation Queue Array-based Implementation Linked Implementation Comparison Fall 2017 Yanjun

More information

Lecture 9 Stacks & Queues

Lecture 9 Stacks & Queues Lecture 9 Stacks & Queues 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning, André Platzer, Rob Simmons In this lecture we introduce queues and stacks as data structures, e.g.,

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Fall 2011 9a-11a, Wednesday, November 2 Name: NetID: Lab Section

More information

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

Ch. 18: ADTs: Stacks and Queues. Abstract Data Type Ch. 18: ADTs: Stacks and Queues CS 2308 Fall 2011 Jill Seaman Lecture 18 1 Abstract Data Type A data type for which: - only the properties of the data and the operations to be performed on the data are

More information

PA3 Design Specification

PA3 Design Specification PA3 Teaching Data Structure 1. System Description The Data Structure Web application is written in JavaScript and HTML5. It has been divided into 9 pages: Singly linked page, Stack page, Postfix expression

More information

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

Queues 4/11/18. Many of these slides based on ones by Cynthia Lee Queues 4/11/18 Many of these slides based on ones by Cynthia Lee Administrivia HW 4 due tomorrow night (list implementations) Reading: For Friday: Beginning of Chapter 7 (pp. 198-211) For Monday: Rest

More information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

Chapter 9 STACK, QUEUE

Chapter 9 STACK, QUEUE Chapter 9 STACK, QUEUE 1 LIFO: Last In, First Out. Stacks Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP. Stack

More information

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

Name CPTR246 Spring '17 (100 total points) Exam 3 Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in

More information

Stacks and Queues. David Greenstein Monta Vista

Stacks and Queues. David Greenstein Monta Vista Stacks and Queues David Greenstein Monta Vista Stack vs Queue Stacks and queues are used for temporary storage, but in different situations Stacks are Used for handling nested structures: processing directories

More information

Postfix (and prefix) notation

Postfix (and prefix) notation Postfix (and prefix) notation Also called reverse Polish reversed form of notation devised by mathematician named Jan Łukasiewicz (so really lü-kä-sha-vech notation) Infix notation is: operand operator

More information

CS350 - Exam 1 (100 Points)

CS350 - Exam 1 (100 Points) Spring 2013 Name CS350 - Exam 1 (100 Points) 1.(25 points) Stacks and Queues (a) (5) For the values 4, 8, 2, 5, 7, 3, 9 in that order, give a sequence of push() and pop() operations that produce the following

More information

ADTs: Stacks and Queues

ADTs: Stacks and Queues Introduction to the Stack ADTs: Stack: a data structure that holds a collection of elements of the same type. - The elements are accessed according to LIFO order: last in, first out - No random access

More information

Queues and Unit Testing

Queues and Unit Testing Queues and Unit Testing Shreya Shankar Stanford CS 106B 3 July 2018 Based on slides created by Ashley Taylor, Marty Stepp, Chris Gregg, Keith Schwarz, Julie Zelenski, Jerry Cain, Eric Roberts, Mehran Sahami,

More information

8. Fundamental Data Structures

8. Fundamental Data Structures 172 8. Fundamental Data Structures Abstract data types stack, queue, implementation variants for linked lists, [Ottman/Widmayer, Kap. 1.5.1-1.5.2, Cormen et al, Kap. 10.1.-10.2] Abstract Data Types 173

More information

Lecture 4 Stack and Queue

Lecture 4 Stack and Queue Lecture 4 Stack and Queue Bo Tang @ SUSTech, Spring 2018 Our Roadmap Stack Queue Stack vs. Queue 2 Stack A stack is a sequence in which: Items can be added and removed only at one end (the top) You can

More information

lecture30: Beyond CS 225

lecture30: Beyond CS 225 lecture30: Beyond CS 225 Sean Massung CS 225 UIUC 31st July, 2013 Announcements lab graphs due tomorrow, 8/1 at 11pm final exam this Friday (8/2), 10:30am-12:30pm in this room Anything but Hello World

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

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

Abstract Data Types. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Abstract Data Types CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues

More information

Lecture 9 Notes Stacks & Queues

Lecture 9 Notes Stacks & Queues Lecture 9 Notes tacks & Queues 15-122: Principles of Imperative Computation (ummer 1 2015) Frank Pfenning, André Platzer, Rob immons 1 Introduction In this lecture we introduce queues and stacks as data

More information

! 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)

! 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) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to:! Determine if a number is odd or even CS 2308 Fall 2018 Jill Seaman! Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

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

CMSC 341. Deques, Stacks and Queues 9/22/04 1 CMSC 341 Deques, Stacks and Queues 9/22/04 1 The Double-Ended Queue ADT The double ended queue is referred to as a Deque (rhymes with check ) Restricted List add to the end remove from the end add to the

More information

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

COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 Lab topic: 1) Take Quiz 4 2) Discussion on Assignment 2 Discussion on Assignment 2. Your task is to

More information

Abstract Data Types 1

Abstract Data Types 1 Abstract Data Types 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues 2 Primitive vs. Abstract Data Types Primitive DT: programmer ADT: programmer Interface (API) data Implementation (methods) Data

More information

Stacks and Queues. CSE 373 Data Structures Lecture 6

Stacks and Queues. CSE 373 Data Structures Lecture 6 Stacks and Queues CSE 373 Data Structures Lecture 6 Readings and References Reading Sections 3.3 and 3.4 10/11/02 Stacks and Queues - Lecture 6 2 Stacks A list for which Insert and Delete are allowed only

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Today s Topics HW Tips QT Creator dos & don ts ADTs Stack Example: Reverse-Polish Notation calculator Queue Event queues QT Creator A F E W W A R N I N

More information

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

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 13 Merging using Queue ADT and Queue types In the

More information

Lecture 9 Stacks & Queues

Lecture 9 Stacks & Queues Lecture 9 Stacks & Queues 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning, André Platzer, Rob Simmons In this lecture we introduce queues and stacks as data structures, e.g., for

More information