ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Stacks, Queues, and Linked Lists
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
CSCE 3110 Data Structures & Algorithm Analysis Stacks and Queues Reading: Chap.3 Weiss.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
A queue is an ADT which allows data values to be accessed only one at a time and only the first inserted. The rule imposed on a queue is: First In First.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Data Structure Dr. Mohamed Khafagy.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
 Balancing Symbols 3. Applications
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Advanced Data Structures
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 16 Stacks and Queues Saurav Karmakar Spring 2007.
Objectives of these slides:
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Data Structures and Algorithm Analysis Lecturer: Jing Liu Homepage:
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Chapter 16 Stacks & Queues. Objective In this chapter we will learn:  Stacks  Queues  Different implementations (arrays and linked list) of both 
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
CE 221 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
 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.
STACKS & QUEUES for CLASS XII ( C++).
Review Array Array Elements Accessing array elements
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
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.
Chapter 15 Lists Objectives
Stacks and Queues.
Queues Queues Queues.
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
Introduction to Data Structure
CMSC 341 Lecture 5 Stacks, Queues
Stacks and Queues CSE 373 Data Structures.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
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.
Stacks and Queues 1.
CSE 373 Data Structures Lecture 6
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
CE 221 Data Structures and Algorithms
Stacks and Queues CSE 373 Data Structures.
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
CSE 373 Data Structures Lecture 6
DATA STRUCTURES IN PYTHON
Presentation transcript:

ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues

= + ADT : An abstract data type (ADT) is a set of objects together with a set of operations. Problem Data Structure (ADT) Algorithm Graph = (V, E) Tree Binary Tree Binary Search Tree Balanced BST

Note – Logical relationship between elements. = Linear ADT Linear Direct AccessArray / Set Sequential AccessList Stack (Fire In Last Out) Queue (Fire In First Out) Non-LinearTree / Graph

1. List List : A list is an abstract data type that implements a finite ordered collection of values, where the same value may occur more than once. Operations - printList() - makeEmpty() - Find() = Search - Insert() - Delete / Remove()

1. List Implement ① Array ② Linked List SortedUnsorted printListO(N) FindO(logN)O(N) InsertO(N)O(1) DeleteO(N) SortedUnsorted printListO(N) FindO(N) InsertO(1) DeleteO(N)

2. Stack (LIFO) Stack : A special case of a List A stack is a particular kind of abstract data type or collection in which the principal (or only) operations on the collection are the addition of an entity to the collection, known as push and removal of an entity, known as pop. Simple representation of a stack

2. Stack Operations Implement - Insert() -> Push() - Delete() -> Pop() - Top() - IsEmpty() - IsFull() ArraySingle-Linked List Push()O(1) Pop()O(1) Top()O(1) IsEmpty()O(1) IsFull()O(1)

2. Stack Mathematic Expression ① infix expression -> A+B ② postfix expression -> AB+ ③ prefix expression -> +AB * Evaluate a postfix expression -> We have to use a stack infixpostfixresult stack

3. Queues: (FIFO) These are special case of lists. In a queue, the insertion is done at one end and deletion is done at the other end. Dequeue Enqueue < < Queue

Operations (Queue) 1.Enqueue ……………. O (1) 2.Dequeue …………... O (1) 3.IsEmpty …………..... O (1) 4.IsFull …………………. O (1) Enqueue : Inserts an element at the end of the list called the rear. Dequeue: Deletes the element at the start of the list called as front.

Implementation of Queues:Array vs. Single Linked List In Queue, same like stacks, both the linked list and array implementations give fast O(1) running times for every operation. Example: For each queue data structure, we keep an array “thearray” positions “front” and “back” which represents the ends of the queue, number of elements in the queue “currentsize” To enqueue an element “X”, increment currentsize and back then set thearray[back]= X. To dequeue an element, set the return value to thearray[front], decrement currentsize and then increment front. There arises a problem with this implementation, after several times of performing enqueue operation the queue will be full since back is now at the last array index, the next queue would be in a non existing position. The simple solution to this problem is that whenever front or back gets to the end of array, it is wrapped around to the beginning, know as Circular array implementation.

1 2 4 After enqueue(1) 24 Initial state After enqueue(3) After dequeue, which returns After dequeue, which returns 4

After dequeue, which returns After dequeue, which returns 3 and makes queue empty

How to distinguish queue is empty to queue is full? For an array, Use upto n-1 items Use “counter” to keep track of # number of items in a queue If counter=0 then, array is full. If counter=1 then, array is empty. Applications of Queues: There are many algorithms to give efficient running times. 1.Generally all waiting lines which we see around is a queue. For instance, Waiting line at a ticket counter are queues, because they follow first come first serve rule. 2.Calls to large companies are generally placed on a queue when all operators are busy. 3.Jobs sent to a line printer are placed on a queue.