Stack, Queues, and Priority Queues: Linked List Based 10-24-2002.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Stacks using Linked Lists. Stack Data Structure As we already know, stacks are linear data structures. This means that their contexts are stored in what.
Computer Science 112 Fundamentals of Programming II Queues and Priority Queues.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
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.
Introduction to C Programming CE Lecture 12 Circular Queue and Priority Queue Data Structures.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
CS Data Structures II Review COSC 2006 April 14, 2017
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
Queues and Priority Queues
Data Structures & Algorithms
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.
Summary of lectures (1 to 11)
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
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.
Stacks, Queues, and Deques. 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.
Stacks, Queues, and Deques
Tutorial 5 Linked List Variations, Stack, & Queue.
Computer Science 2 Data Structures and Algorithms V Intro to “big o” Lists Professor: Evan Korth New York University 1.
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
Queues and Priority Queues
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
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)
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
COMP 103 Priority Queues, Partially Ordered Trees and Heaps.
Recursion Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zWhat is a recursive function?
String Processing Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have questions.
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’
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Recursion Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? Don’t let problems hang.
AVL Trees Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignments? zYour minute essay last.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
Stacks and Queues. Announcements USACO Open competition results are out o Congrats to Johnny for scoring 2nd in the US USACO Finalists are also announced.
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Programming Abstractions Cynthia Lee CS106X. Topics:  Priority Queue › Linked List implementation › Heap data structure implementation  TODAY’S TOPICS.
Queues. Like Stacks, Queues are a special type of List for storing collections of entities. Stacks are Lists where insertions (pushes) and deletions (pops)
Arrays: Part Opening Discussion zWhat did we talk about last class? zWhat do you think the picture of memory looks like when we declare.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Conditionals Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zPass by value limitations.
Understanding General Software Development Lesson 3.
Stack and Queues Part 2. Priority Queues Priority Queues (cont’) A priority queue is a more specialized data structure than a stack or a queue. However,
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Linear Data Structures
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Mergesort and Quicksort Opening Discussion zWhat did we talk about last class? zDo you have any questions about assignment #4? Have you thought.
Maximum Flow and Dynamic Programming Opening Discussion zWho can describe a flow network to me. What are the properties it has and what types.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Priority Queues Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignments? The designs for assignment.
Understanding General Software Development Lesson 3.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queues.
Programming Abstractions
Queue and Priority Queue Implementations
Chapter 14: Queue and Priority Queue Implementations
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
CSE 12 – Basic Data Structures
Data Structures & Programming
Presentation transcript:

Stack, Queues, and Priority Queues: Linked List Based

Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zI’m going to be leaving campus right after class to fly to the D.C. area and I won’t have access during the weekend so asking questions now could be vital.

O(f(n)) Notation zWhen we say that an algorithm is of the order of some function of n, what we are saying is that the number of operations it does grows with the input size in the same way that function does. zIt is called an asymptotic notation because it is most accurate for large n and we throw away all coefficients and only keep the largest terms.

Stacks as Linked Lists zWe have looked at how we can implement the Stack interface with an array, but we can also do it with a linked list. zFor a linked list stack, we only need a head pointer and all the pushes and pops go on it or pull from it. zThe main conceptual difference from an array based stack is just which “end” we are pushing to and popping from.

Queues as Linked Lists zQueues with arrays required a bit of extra thinking to make them circular. They are actually easier with a linked list. zWe keep both a head and a tail. One is the front and the other is the back of the queue. To figure out which is which, think about which one you can easily remove from. zWe make the choice because we want O(1) operations.

The Priority Queue ADT zAn ADT that is slightly more advanced than the Stack or Queue is the Priority Queue. This ADT acts like a queue, but with the added complication that the elements have a priority. zWhen elements are removed from it, it is always the highest (or lowest) priority element that is taken out next. zWe want be be able to find that element fast. Fast adds are nice too.

Sorted Linked Lists zWe can easily make a linked list data structure that is sorted by modifying the insert method so that it inserts the new node into the proper position in the list to be sorted. zBuilding a sorted linked list is almost like an insertion sort. The problem is that the insert is a O(n) operation.

Using SLLs for Priority Queues zIf we build a sorted list based on priority, then it automatically works as a priority queue. Items are always removed from the front of the list and inserted where they belong in the list. zThis gives fast, O(1), removes, but the adding is O(n). We’ll look at a faster alternative later in the semester.

Code zNow we will look at code for some of these things.

Minute Essay zHow do you think the linked list based queues and stacks compare to those we looked at using arrays? zRemember that design #5 is due today. zHave a great fall break.