308-203A Introduction to Computing II Lecture 6: Lists, Stacks, and Queues Fall Session 2000.

Slides:



Advertisements
Similar presentations
Data Structure HKOI training /4/2010 So Pak Yeung.
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
TCSS 342, Winter 2005 Lecture Notes
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
CS 1031 Queues Definition of a Queue Examples of Queues Design of a Queue Class Different Implementations of the Queue Class.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
Stacks and Queues Introduction to Computing Science and Programming I.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
1/ 124 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 18 Programming Fundamentals using Java 1.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
1 Data Structures - Part II CS215 Lecture #8. Stacks  Last-In-First-Out (LIFO)  Stacks are often used in programming when data will need to be used.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
AITI Lecture 18 Introduction to Data Structure, Stack, and Queue Adapted from MIT Course 1.00 Spring 2003 Lecture 23 and Tutorial Note 8 (Teachers: Please.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
1ADS Lecture 11 Stacks contd.. ADS Lecture 113 Singly Linked list-based Stack Top of stack is head of list (can insert elements at head in constant.
Linear Data Structures
CS-2852 Data Structures LECTURE 5 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Stacks and Queues. DCS – SWC 2 Stacks A stack is an abstract data structure, with some special properties: –Insertion and deletion is only allowed at.
Review Array Array Elements Accessing array elements
Cpt S 122 – Data Structures Abstract Data Types
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Program based on queue & their operations for an application
Chapter 15 Lists Objectives
Stacks and Queues CMSC 202.
Stacks and Queues.
Stacks and Queues.
Stack and Queue Author : Srinadh Gunnam.
Pointers and Linked Lists
Lesson Objectives Aims
ITEC 2620M Introduction to Data Structures
Stacks and Queues.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Stacks.
DATA STRUCTURES IN PYTHON
Presentation transcript:

A Introduction to Computing II Lecture 6: Lists, Stacks, and Queues Fall Session 2000

To glue data together... ValueNext Node = List = a chain of nodes abcd

Terminology abcd “head” “tail” “links”

Possible Operations on Lists Locate an element Check if empty Check the number of items in the list Concatenate lists together Insert an element (where?) Delete an element (how is it referred to?)

A Simple Java Implementation Class Node { Object value; Node next; // methods …. } Class List { Node head; // methods …. }

Orders of Growth Q1. What is the complexity of adding an item at the head of a list? Q2. What is the complexity of adding an item at the tail of a list? Q3. In general?

Orders of Growth Q1. What is the complexity of adding an item at the head of a list? Q2. What is the complexity of adding an item at the tail of a list? Q3. In general? A1. O(1) A2. O(n) A3. O(n)

A Variation: Doubly Linked Lists abcd ValueNext Node = Previous

Orders of Growth Q1. What is the complexity of adding an item at the head of a doubly-linked list? Q2. What is the complexity of adding an item at the tail of a doubly-linked list? Q3. In general?

Orders of Growth Q1. What is the complexity of adding an item at the head of a doubly-linked list? Q2. What is the complexity of adding an item at the tail of a doubly-linked list? Q3. In general? A1. O(1) A2. O(1) A3. O(n)

Stacks Definition: A stack is a list which is accessed only by the two following methods: 1. Push - insert an element at the head 2. Pop - remove the most recently “pushed” element

Stacks - the intuition Think of pancakes on a plate Empty a Push(a) Push(b) a b Push(c) a b c Pop( ) a b a c b

Why do we care? A stack has less functionality than a list (because we only pop and push) but it’s enough to do some important things: 1. Reverse Polish Notation calculators 2. This is really what happens when you call a function or method 3. CS Profs like to ask questions about stacks on exams.

Definition: A queue is a list which is accessed only by the two following methods, which preserve a First-In First-Out or “FIFO” order: 1. Insert - insert an element at one end 2. Dequeue - remove the “oldest” element (= the one at the other end of the list) Queues (aka FIFO)

Queues The intuition: this is what you do when you’re waiting in line at the grocery store Customers in Cashiers service customers Queue a bcd ( = INSERT) ( = DEQUEUE)

Why do we care? Whenever you’ve got a lot of tasks to do, putting them in a queue and servicing them in FIFO order guarantees that no task goes forever unfinished…. True for HTTP requests on a webserver as for the client in line at the bank.

Orders of growth?? Q1. What is the complexity of the two queue operations if there is an underlying (singly-linked) list? Q2. If it’s a doubly-linked list??

Orders of growth?? Q1. What is the complexity of the two queue operations if there is an underlying (singly-linked) list? Q2. If it’s a doubly-linked list?? One is O(n), the other O(1) Both O(1)

A Class Hierarchy of List-Like Objects SimpleList ListStackQueue This lives on our website under “Examples”

Any questions?