CSE 131 Computer Science 1 Module 9a: ADT Representations. Stack and queue ADTs array implementations Buffer ADT and circular lists

Size: px
Start display at page:

Download "CSE 131 Computer Science 1 Module 9a: ADT Representations. Stack and queue ADTs array implementations Buffer ADT and circular lists"

Transcription

1 CSE 11 Computer Science 1 Module 9a: ADT Representations Stack and queue ADTs array implementations Buffer ADT and circular lists

2 Buffer ADT add and remove from both ends»can grow and shrink from either end»cannot access middle, e.g. find(p)»may wrap in either direction first count=4 This yields buffer ADT, also sometimes called a doubleended queue (or deque, which is pronounced deck ) Operations include»getfirst(), getlast()»addfirst(x), addlast(x),»removefirst(), removelast() Again, constant time per operation»note, not true if we just used ArrayList in place of Buffer

3 The Stack Abstract Data Type A stack is a data structure that stores a collection of items and supports the following operations»push(x) add item x onto the top of the stack»pop() remove the item currently on top of the stack»peek() return the item that is currently at the top of the stack peek()= push() push(0) 0 pop»sequence: push(x), then i pushes, then i pops gives peek()=x Special case of the List ADT so why bother?»often easier to understand (and correctly implement) programs that use just the right data structure restrictions reduce bugs»specialized versions can be implemented more efficiently

4 The Queue Abstract Data Type A queue is a data structure that stores a collection of items and supports the following operations»enqueue(x) add item x to the tail of the queue»peek() return the item that is at the head of the queue»dequeue() remove the item at the head of the queue peek()= enqueue(6) dequeue() 6 6»sequence: enqueue(x), enqueue(y) is eventually followed by peek()=x and next dequeue() yields peek()=y»queues often used to link multiple stages of a computation 4

5 Implement Buffer, Stack, Queue using List Suppose you have a List that implements»getfirst(), getlast()»addfirst(x), addlast(x),»removefirst(), removelast() We can implement a buffer by simple passing-through addlast(object x) { list.addlast(x); We do not expose other details of the List to the buffer Stack: push addfirst(), peek getfirst(), pop removefirst() Queue: enqueue addlast(), peek getfirst(), dequeue removefirst()

6 Array-Based Stack Implementation Array implementation of stacks is simple and efficient»instance variable top stores index of top element»peek() returns stackarray[top]»push(x): stackarray[++top]=x»pop(): top»add tests to avoid overflow/underflow»isempty() returns (top == 1) Constant time per operation»that is, pushing an item onto a stack with a million items takes same time as for a stack with two items»true because items only added/removed at top of stack In Java, stacks of objects store objects separately from the array top stackarray abc def xyz 6

7 Array-Based Queue Implementation Array implementation of queue is simple and efficient»instance variable head points to first item in queue; tail points to item»count is # of elements in the queue»head and tail wrap around at end of array»peek() returns qarray[head]»enqueue(x): tail=(tail+1)%size; qarray[tail]=x»dequeue(): head=(head+1)%size Again, constant time per operation since items are only added/removed from ends Queues of objects store objects separately from the array head 4 6 tail 6 count=4 tail head count=4

8 Comparing ADT Implementations Stack Queue Buffer ArrayList LinkedList getfirst X constant constant constant constant getlast constant X constant constant constant addfirst X X constant linear constant addlast constant constant constant constant constant removefirst X constant constant linear constant removelast constant X constant constant constant add anywhere X X X linear constant remove any item X X X linear constant access by position X X X constant linear Constant means time is independent of # of elements Linear means time grows in proportion to # of elements in the worst-case 8

9 Circular Lists Array-based implementations require allocating space when data structure is constructed»often, don t know how much space is needed in advance»linked lists allow stacks/queues/buffers to grow and shrink as needed Circular lists are a natural choice for stacks/queues»usually implemented with pointer to item»makes addfirst(), addlast(), removefirst() easy»removelast() requires going all the way around (or does it?) addlast(8) removefirst() 9

10 public class CircularList(){ public ListItem ; public void addlast(int x){ if( == null) { = new ListItem(x, null);.next = ; else {.next = new ListItem(x,.next); =.next; 8 addlast(8) 10

11 public void addfirst(int x){ if( == null) { = new ListItem(x, null);.next = ; else {.next = new ListItem(x,.next); 8 addfirst(8) 11

12 public int getfirst(){ if( == null) throw new EmptyException(); return.next.value; public int removefirst() { int x = getfirst();.next =.next.next; return x; 8 8 getfirst() is removefirst() 1

13 Implement Stack using Circular List public class Stack { private CircularList elements = new CircularList(); public void push(x) {elements.addfirst(x); public int pop() {return elements.removefirst(); public int peek() {return elements.getfirst(); 1

14 Implement Queue using Circular List public class Queue { private CircularList elements = new CircularList(); public void enqueue(x) {elements.addlast(x); public int dequeue) { return elements.removefirst(); public int peek() {return elements.getfirst(); 14

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

Computer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures

Computer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures Computer Science 210 Data Structures Siena College Fall 2018 Topic Notes: Linear Structures The structures we ve seen so far, Vectors/ArrayLists and linked list variations, allow insertion and deletion

More information

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER

More information

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Chapter 5: Stacks, ueues and Deques Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,

More information

Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018

Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018 CS 61B Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018 1 Assorted ADTs A list is an ordered collection, or sequence. 1 interface List { 2 boolean add(e element); 3 void add(int index,

More information

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a

More information

Queue. COMP 250 Fall queues Sept. 23, 2016

Queue. COMP 250 Fall queues Sept. 23, 2016 Queue Last lecture we looked at a abstract data type called a stack. The two main operations were push and pop. I introduced the idea of a stack by saying that it was a kind of list, but with a restricted

More information

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal Queues COL 106 Slides by Amit Kumar, Shweta Agrawal The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out (FIFO) scheme Insertions are at the rear

More information

COMP 250 Midterm #2 March 11 th 2013

COMP 250 Midterm #2 March 11 th 2013 NAME: STUDENT ID: COMP 250 Midterm #2 March 11 th 2013 - This exam has 6 pages - This is an open book and open notes exam. No electronic equipment is allowed. 1) Questions with short answers (28 points;

More information

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Lists and Iterators CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Announcements Should be making progress on VectorGraphics. Should have turned in CRC cards,

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

1/22/13. Queue? CS 200 Algorithms and Data Structures. Implementing Queue Comparison implementations. Photo by David Jump 9. Colorado State University

1/22/13. Queue? CS 200 Algorithms and Data Structures. Implementing Queue Comparison implementations. Photo by David Jump 9. Colorado State University //3 Part Queues CS Algorithms and Data Structures Outline Queue? Implementing Queue Comparison implementations 8 Photo by David Jump 9 //3 "Grill the Buffs" event Queue A queue is like a line of people

More information

1/22/13. Queue. Create an empty queue Determine whether a queue is empty Add a new item to the queue

1/22/13. Queue. Create an empty queue Determine whether a queue is empty Add a new item to the queue Outline Part Queues Queue? Implementing Queue Comparison implementations CS Algorithms and Data Structures 8 "Grill the Buffs" event Photo by David Jump 9 Queue A queue is like a line of people New item

More information

Assignment 1. Check your mailbox on Thursday! Grade and feedback published by tomorrow.

Assignment 1. Check your mailbox on Thursday! Grade and feedback published by tomorrow. Assignment 1 Check your mailbox on Thursday! Grade and feedback published by tomorrow. COMP250: Queues, deques, and doubly-linked lists Lecture 20 Jérôme Waldispühl School of Computer Science McGill University

More information

Stacks and queues (chapters 6.6, 15.1, 15.5)

Stacks and queues (chapters 6.6, 15.1, 15.5) Stacks and queues (chapters 6.6, 15.1, 15.5) So far... Complexity analysis For recursive and iterative programs Sorting algorithms Insertion, selection, quick, merge, (intro, dual-pivot quick, natural

More information

Department of Computer Science and Engineering. CSE 2011: Fundamentals of Data Structures Winter 2009, Section Z

Department of Computer Science and Engineering. CSE 2011: Fundamentals of Data Structures Winter 2009, Section Z Department of omputer Science and Engineering SE 2011: Fundamentals of Data Structures Winter 2009, Section Z Instructor: N. Vlajic Date: pril 14, 2009 Midterm Examination Instructions: Examination time:

More information

Queue? Part 4. Queues. Photo by David Jump. Create an empty queue Items leave a queue from its front.

Queue? Part 4. Queues. Photo by David Jump. Create an empty queue Items leave a queue from its front. /3/ Outline Queue? Part Queues Implementing Queue Comparison implementations CS Algorithms and Data Structures "Grill the Buffs" event 9/ 3 Photo by David Jump Queue OperaLons A queue is like a line of

More information

Adam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions

Adam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions Adam Blank Lecture 1 Winter 2017 CSE 332 Data Abstractions CSE 332: Data Abstractions Welcome to CSE 332! Outline 1 Administrivia 2 A Data Structures Problem 3 Review of Stacks & Queues What Am I Getting

More information

Notes on access restrictions

Notes on access restrictions Notes on access restrictions A source code file MyClass.java is a compilation unit and can contain at most one public class. Furthermore, if there is a public class in that file, it must be called MyClass.

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ JAVA PROJECT 2 Organizational Details exam =

More information

.:: UNIT 4 ::. STACK AND QUEUE

.:: UNIT 4 ::. STACK AND QUEUE .:: UNIT 4 ::. STACK AND QUEUE 4.1 A stack is a data structure that supports: Push(x) Insert x to the top element in stack Pop Remove the top item from stack A stack is collection of data item arrange

More information

Linked Structures. See Section 3.2 of the text.

Linked Structures. See Section 3.2 of the text. Linked Structures See Section 3.2 of the text. First, notice that Java allows classes to be recursive, in the sense that a class can have an element which is itself an object of that class: class Person

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

CS/CE 2336 Computer Science II

CS/CE 2336 Computer Science II CS/CE 2336 Computer Science II UT D Session 11 OO Data Structures Lists, Stacks, Queues Adapted from D. Liang s Introduction to Java Programming, 8 th Ed. 2 What is a Data Structure? A collection of data

More information

Abstract Data Types - Lists Arrays implementation Linked-lists implementation

Abstract Data Types - Lists Arrays implementation Linked-lists implementation Abstract Data Types - Lists Arrays implementation Linked-lists implementation Lecture 17 Jérôme Waldispühl School of Computer Science McGill University From slides by Mathieu Blanchette Abstract data types

More information

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please

More information

CMPT 125: Practice Midterm Answer Key

CMPT 125: Practice Midterm Answer Key CMPT 125, Spring 2017, Surrey Practice Midterm Answer Key Page 1 of 6 CMPT 125: Practice Midterm Answer Key Linked Lists Suppose you have a singly-linked list whose nodes are defined like this: struct

More information

CSC212:Data Structure

CSC212:Data Structure CSC212:Data Structure 1 Queue: First In First Out (FIFO). Used in operating systems, simulations etc. Priority Queues: Highest priority item is served first. Used in operating systems, printer servers

More information

Lecture 12: Doubly Linked Lists

Lecture 12: Doubly Linked Lists Lecture 12: Doubly Linked Lists CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Doubly Linked List A linked list consisting of a sequence of nodes, starting from a head pointer and ending to a

More information

Lecture 4. The Java Collections Framework

Lecture 4. The Java Collections Framework Lecture 4. The Java s Framework - 1 - Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework - 2 - Learning Outcomes From this lecture you should

More information

ITI Introduction to Computing II

ITI Introduction to Computing II index.pdf March 17, 2013 1 ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 17, 2013 Definitions A List is a linear abstract

More information

COMP 250. Lecture 8. stack. Sept. 25, 2017

COMP 250. Lecture 8. stack. Sept. 25, 2017 COMP 250 Lecture 8 stack Sept. 25, 2017 1 get(i) set(i,e) add(i,e) remove(i) remove(e) clear() isempty() size() What is a List (abstract)? // Returns the i-th element (but doesn't remove it) // Replaces

More information

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print) Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked

More information

Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on

Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on Lecture 16 Jérôme Waldispühl School of Computer Science McGill University Slides by Mathieu BlancheIe Recap from last lecture

More information

Introduction to Data Structures. Introduction to Data Structures. Introduction to Data Structures. Data Structures

Introduction to Data Structures. Introduction to Data Structures. Introduction to Data Structures. Data Structures Philip Bille Data Structures Data structure. Method for organizing data for efficient access, searching, manipulation, etc. Goal. Fast. Compact Terminology. Abstract vs. concrete data structure. Dynamic

More information

HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS

HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS SYLLABUS ABSTRACT DATA TYPES (ADTS) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations

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

Implementing Lists, Stacks, Queues, and Priority Queues

Implementing Lists, Stacks, Queues, and Priority Queues Implementing Lists, Stacks, Queues, and Priority Queues CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 1 Objectives To design common features of lists in

More information

Linked List Implementation of Queues

Linked List Implementation of Queues Outline queue implementation: linked queue application of queues and stacks: data structure traversal double-ended queues application of queues: simulation of an airline counter random numbers recursion

More information

Queue Implemented with a CircularArray. Queue Implemented with a CircularArray. Queue Implemented with a CircularArray. Thursday, April 25, 13

Queue Implemented with a CircularArray. Queue Implemented with a CircularArray. Queue Implemented with a CircularArray. Thursday, April 25, 13 Queue Implemented with 1 2 numitems = enqueue (); 1 Queue Implemented with 2 numitems = 2 enqueue (); enqueue (); 2 Queue Implemented with 2 numitems = 2 enqueue (); enqueue (); enqueue (5); enqueue (6);

More information

An Introduction to Data Structures

An Introduction to Data Structures An Introduction to Data Structures Advanced Programming ICOM 4015 Lecture 17 Reading: Java Concepts Chapter 20 Fall 2006 Adapded from Java Concepts Companion Slides 1 Chapter Goals To learn how to use

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

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

CMSC Introduction to Algorithms Spring 2012 Lecture 7

CMSC Introduction to Algorithms Spring 2012 Lecture 7 CMSC 351 - Introduction to Algorithms Spring 2012 Lecture 7 Instructor: MohammadTaghi Hajiaghayi Scribe: Rajesh Chitnis 1 Introduction In this lecture we give an introduction to Data Structures like arrays,

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

Generics. IRS W-9 Form

Generics. IRS W-9 Form Generics IRS W-9 Form Generics Generic class and methods. BNF notation Syntax Non-parametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]

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

Data Structures Lecture 5

Data Structures Lecture 5 Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 5 Announcement Project Proposal due on Nov. 9 Remember to bring a hardcopy

More information

package weiss.util; // Fig , pg // Fig 6.16,6.17, pg package weiss.util;

package weiss.util; // Fig , pg // Fig 6.16,6.17, pg package weiss.util; package weiss.util; // Fig 6.9-10, pg 192-4. public interface Collection extends java.io.serializable int size( ); boolean isempty( ); boolean contains( Object x ); boolean add( Object x ); boolean remove(

More information

CMSC 132: Object-Oriented Programming II. Stack and Queue

CMSC 132: Object-Oriented Programming II. Stack and Queue CMSC 132: Object-Oriented Programming II Stack and Queue 1 Stack Allows access to only the last item inserted. An item is inserted or removed from the stack from one end called the top of the stack. This

More information

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi Stack and Queue How do we implement a Queue using Array? : A collection of nodes with linear ordering defined on them. Each node holds an element and points to the next node in the order. The first node

More information

Doubly LinkedList is Symmetrical! LinkedList Efficiency. Monday, April 8, 13. insert insert remove remove remove walk

Doubly LinkedList is Symmetrical! LinkedList Efficiency. Monday, April 8, 13. insert insert remove remove remove walk How Can We Improve the State of Experimental Evaluation in Computer Siene Peter Sweeney IBM Researh, TJ Watson Friday, April 12, 12:00 Kendade 307 1 Doubly LinkedList is Symmetrial! insert insert remove

More information

182 review 1. Course Goals

182 review 1. Course Goals Course Goals 182 review 1 More experience solving problems w/ algorithms and programs minimize static methods use: main( ) use and overload constructors multiple class designs and programming solutions

More information

Dynamic Data Structures

Dynamic Data Structures Dynamic Data Structures We have seen that the STL containers vector, deque, list, set and map can grow and shrink dynamically. We now examine how some of these containers can be implemented in C++. To

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures

Computer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Linear Structures The structures we ve seen so far, Vectors/ArrayLists and linked lists, allow insertion and deletion of elements

More information

The Java Collections Framework. Chapters 7.5

The Java Collections Framework. Chapters 7.5 The Java s Framework Chapters 7.5 Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework Outline Introduction to the Java s Framework Iterators Interfaces,

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

COMP 250. Lecture 6. doubly linked lists. Sept. 20/21, 2017

COMP 250. Lecture 6. doubly linked lists. Sept. 20/21, 2017 COMP 250 Lecture 6 doubly linked lists Sept. 20/21, 2017 1 Singly linked list head tail 2 Doubly linked list next prev element Each node has a reference to the next node and to the previous node. head

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 13 Fall 2018 Instructors: Bill 2

CSCI 136 Data Structures & Advanced Programming. Lecture 13 Fall 2018 Instructors: Bill 2 CSCI 136 Data Structures & Advanced Programming Lecture 13 Fall 2018 Instructors: Bill 2 Announcements Lab today! After mid-term we ll have some non-partner labs It s Lab5 not Lab 4 Mid-term exam is Wednesday,

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

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,

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

Computer Science 210: Data Structures. Linked lists

Computer Science 210: Data Structures. Linked lists Computer Science 210: Data Structures Linked lists Arrays vs. Linked Lists Weʼve seen arrays: int[] a = new int[10]; a is a chunk of memory of size 10 x sizeof(int) a has a fixed size a[0] a[1] a[2]...

More information

csci 210: Data Structures Linked lists Summary Arrays vs. Lists Arrays vs. Linked Lists a[0] a[1] a[2]... null Today READING: Arrays

csci 210: Data Structures Linked lists Summary Arrays vs. Lists Arrays vs. Linked Lists a[0] a[1] a[2]... null Today READING: Arrays Summary Today linked lists csci 210: Data Structures Linked lists single-linked lists double-linked lists circular lists READING: LC chapter 4.1, 4.2, 4.3 Arrays vs. Linked Lists Arrays vs. Lists We!ve

More information

Computer Science 62. Midterm Examination

Computer Science 62. Midterm Examination Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 Your name (Please print) 1. Suppose you are given a singly-linked list

More information

CSC 273 Data Structures

CSC 273 Data Structures CSC 273 Data Structures Lecture 7 - Queues, Deques, and Priority Queues The ADT Queue A queue is another name for a waiting line Used within operating systems and to simulate real-world events Come into

More information

LIFO : Last In First Out

LIFO : Last In First Out Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.

More information

Chapter 18: Stacks And Queues

Chapter 18: Stacks And Queues Chapter 18: Stacks And Queues 18.1 Introduction to the Stack ADT Introduction to the Stack ADT Stack: a LIFO (last in, first out) data structure Examples: plates in a cafeteria return addresses for function

More information

JAVA.UTIL.LINKEDLIST CLASS

JAVA.UTIL.LINKEDLIST CLASS JAVA.UTIL.LINKEDLIST CLASS http://www.tutorialspoint.com/java/util/java_util_linkedlist.htm Copyright tutorialspoint.com Introduction The java.util.linkedlist class operations perform we can expect for

More information

CISC 3115 TY3. C24a: Lists. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 11/15/2018 CUNY Brooklyn College

CISC 3115 TY3. C24a: Lists. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 11/15/2018 CUNY Brooklyn College CISC 3115 TY3 C24a: Lists Hui Chen Department of Computer & Information Science CUNY Brooklyn College 11/15/2018 CUNY Brooklyn College 1 Outline Concept of data structure Use data structures List Stack

More information

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved. Data Structures Outline Introduction Linked Lists Stacks Queues Trees Introduction dynamic data structures - grow and shrink during execution Linked lists - insertions and removals made anywhere Stacks

More information

COMP 103. Data Structures and Algorithms

COMP 103. Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2004 END-YEAR COMP 103 Data Structures and Algorithms Time Allowed: 3 Hours Instructions:

More information

Abstract Data Types. Data Str. Client Prog. Add. Rem. Find. Show. 01/22/04 Lecture 4 1

Abstract Data Types. Data Str. Client Prog. Add. Rem. Find. Show. 01/22/04 Lecture 4 1 Abstract Data Types Add Client Prog Rem Find Data Str. Show 01/22/04 Lecture 4 1 Containers Powerful tool for programming data structures Provides a library of container classes to hold your objects 2

More information

CE204 Data Structures and Algorithms Part 2

CE204 Data Structures and Algorithms Part 2 CE204 Data Structures and Algorithms Part 2 14/01/2018 CE204 Part 2 1 Abstract Data Types 1 An abstract data type is a type that may be specified completely without the use of any programming language.

More information

Chapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley 18.1 Introduction to

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

CSC 321: Data Structures. Fall 2012

CSC 321: Data Structures. Fall 2012 CSC 321: Data Structures Fall 2012 Lists, stacks & queues Collection classes: List (ArrayList, LinkedList), Set (TreeSet, HashSet), Map (TreeMap, HashMap) ArrayList performance and implementation LinkedList

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

Array Lists Outline and Required Reading: Array Lists ( 7.1) CSE 2011, Winter 2017, Section Z Instructor: N. Vlajic

Array Lists Outline and Required Reading: Array Lists ( 7.1) CSE 2011, Winter 2017, Section Z Instructor: N. Vlajic rray Lists Outline and Required Reading: rray Lists ( 7.) CSE 20, Winter 207, Section Z Instructor: N. Vlajic Lists in Everyday Life 2 List convenient way to organize data examples: score list, to-do list,

More information

Solutions to a few of the review problems:

Solutions to a few of the review problems: Solutions to a few of the review problems: Problem 1 The interface Deque can have array based and linked implementations. Partial versions of implementation classes follow. Supply implementations for the

More information

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016 COMP 250 Winter 2016 5 generic types, doubly linked lists Jan. 28, 2016 Java generics In our discussion of linked lists, we concentrated on how to add or remove a node from the front or back of a list.

More information

Specifications for the ADT List Ali list provides a way to organize data List of students List of sales List of lists

Specifications for the ADT List Ali list provides a way to organize data List of students List of sales List of lists Abstract Data Type List ADT List Specifications for the ADT List Ali list provides a way to organize data List of students List of sales List of lists A list has first, last, and in between items (the

More information

Introduction to Data Structures

Introduction to Data Structures Introduction to Data Structures Data structures Stacks and Queues Linked Lists Dynamic Arrays Philip Bille Introduction to Data Structures Data structures Stacks and Queues Linked Lists Dynamic Arrays

More information

ECE 2400 Computer Systems Programming Fall 2017 Topic 9: Abstract Data Types

ECE 2400 Computer Systems Programming Fall 2017 Topic 9: Abstract Data Types ECE 2400 Computer Systems Programming Fall 2017 Topic 9: Abstract Data Types School of Electrical and Computer Engineering Cornell University revision: 2017-10-11-11-58 1 Sequence ADTs 2 2 Stack ADTs 5

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

C27a: Stack and Queue

C27a: Stack and Queue CISC 3115 TY3 C27a: Stack and Queue Hui Chen Department of Computer & Information Science CUNY Brooklyn College 11/27/2018 CUNY Brooklyn College 1 Outline Discussed Concept of data structure Use data structures

More information

ADTs, Arrays, and Linked-Lists

ADTs, Arrays, and Linked-Lists ADTs, Arrays, and Linked-Lists EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Abstract Data Type (ADT) abstract implementation details are not specified! Abstract Data Types (ADTs)

More information

Linked Lists

Linked Lists Linked Lists 2-17-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? Can you tell me what a linked list is and what

More information

Introduction to Software Design

Introduction to Software Design CSI 1102 1 Abdulmotaleb El Saddik University of Ottawa School of Information Technology and Engineering (SITE) Multimedia Communications Research Laboratory (MCRLab) Distributed Collaborative Virtual Environments

More information

Computer Science 136 Exam 2

Computer Science 136 Exam 2 Computer Science 136 Exam 2 Sample exam Show all work. No credit will be given if necessary steps are not shown or for illegible answers. Partial credit for partial answers. Be clear and concise. Write

More information

CSC 321: Data Structures. Fall 2013

CSC 321: Data Structures. Fall 2013 CSC 321: Data Structures Fall 2013 Lists, stacks & queues Collection classes: List (ArrayList, LinkedList), Set (TreeSet, HashSet), Map (TreeMap, HashMap) ArrayList performance and implementation LinkedList

More information

Chapter 18: Stacks And Queues

Chapter 18: Stacks And Queues Chapter 18: Stacks And Queues 18.1 Introduction to the Stack ADT Introduction to the Stack ADT Stack a LIFO (last in, first out) data structure Examples plates in a cafeteria return addresses for function

More information

Linked lists. Comp Sci 1575 Data Structures. Definitions. Memory structure. Implementation. Operations. Comparison

Linked lists. Comp Sci 1575 Data Structures. Definitions. Memory structure. Implementation. Operations. Comparison Linked lists Comp Sci 1575 Data Structures Outline 1 2 3 4 5 Linked list Linked lists are of a linear collection of data elements, called nodes, each pointing to the next node Each node is composed of

More information

CMP Points Total Midterm Spring Version (16 Points) Multiple Choice:

CMP Points Total Midterm Spring Version (16 Points) Multiple Choice: Version 1 Instructions Write your name and version number on the top of the yellow paper. Answer all questions on the yellow paper. One question per page. Use only one side of the yellow paper. 1. (16

More information

Queues Fall 2018 Margaret Reid-Miller

Queues Fall 2018 Margaret Reid-Miller Queues 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Writing methods various classes that implement Lists. Methods using Lists and Big-O w/ ArrayList or LinkedLists Prove

More information

Information Science 2

Information Science 2 Information Science 2 - Basic Data Structures- Week 02 College of Information Science and Engineering Ritsumeikan University Today s class outline l Basic data structures: Definitions and implementation

More information

Week 6. Data structures

Week 6. Data structures 1 2 3 4 5 n Week 6 Data structures 6 7 n 8 General remarks We start considering Part III Data Structures from CLRS. As a first example we consider two special of buffers, namely stacks and queues. Reading

More information

Data Structures and Algorithms Notes

Data Structures and Algorithms Notes Data Structures and Algorithms Notes Notes by Winst Course taught by Dr. G. R. Baliga 256-400 ext. 3890 baliga@rowan.edu Course started: September 4, 2012 Last generated: December 18, 2013 Interfaces -

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

ECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types

ECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types ECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types School of Electrical and Computer Engineering Cornell University revision: 2018-10-11-00-24 1 Sequence ADTs 4 1.1. Example C-Based

More information