CS 2412 Data Structures. Chapter 3 Queues
|
|
|
- Austen Dorsey
- 9 years ago
- Views:
Transcription
1 CS 2412 Data Structures Chapter 3 Queues
2 3.1 Definitions A queue is an ordered collection of data in which all additions to the collection are made at one end (called rare or tail) and all deletions from the collection are made at the other end (called front or head). A stack is FILO, while a queue is FIFO (first-in first-out). Data Structure 2014 R. Wei 2
3 Applications: CPU waiting list. Network router packets sequence. Simulations Data Structure 2014 R. Wei 3
4 Main operations: Creation Clear (damage) Append (add element) Serve (remove element) Data Structure 2014 R. Wei 4
5 Specification: void CteateQueue(Queue *q); precondition: None. postcondition: The queue q has been initialized to be empty. (Also can use Queue* CreateQueue(void); ) void ClearQueue(Queue *q); precondition: The queue q has been created. postcondition: All entries have been removed from q and it is now empty. Data Structure 2014 R. Wei 5
6 Boolean QueueEmpty(Queue *q); precondition: The queue has been created. postcondition: The function returns true or false according as queue q is empty or not. Boolean QueueFull(Queue *q); precondition: The queue has been created. postcondition: The function returns true or false according as queue q is full or not. Data Structure 2014 R. Wei 6
7 void Append(QueueEntry x, Queue *q); precondition: The queue has been create and is not full. postcondition: The entry x has been stored in the queue as last entry. void Serve(QueueEntry *x, Queue *q); precondition: The queue has been create and is not empty. postcondition: The first entry has been removed and returned as the value of x. Data Structure 2014 R. Wei 7
8 Some other operations which are not usual operations of a queue. int QueueSize(Queue *q); precondition: The queue has been created. postcondition: The function returns the number of entries in the queue. void QueueFront(QueueEntry *x, Queue *q); precondition: The queue has been created and it is not empty. postcondition: The value of first entry of q is copied to x. The queue remains unchanged. Data Structure 2014 R. Wei 8
9 3.2 Implementations Using an array to implement a queue has some difficulties. If after each Serve every item moves forward, then time consume is big. If the item not moves, the space will be wasted. A circular array can be used to solve that problem. Data Structure 2014 R. Wei 9
10 Circular array implementation To let an array be circular in C, we can use: if(i>=max-1) i=0; else i++; or i=(i+1)% MAX The difficulty is how to know the queue is empty or full if we use a circular array. Data Structure 2014 R. Wei 10
11 We can use a variable count to track of the numbers of entries in a queue to avoid the confusion of full or empty. #define MAXQUEUE 10 typedef char QueueEntry; typedef struct queue int count; int front; int rear; QueueEntry entry[maxqureue]; } Queue; Data Structure 2014 R. Wei 11
12 Prototypes: void CreateQueue(Queue *); void Append(QueueEntry,Queue *); void Serve(QueueEntry *,Queue *); Boolean QueueEmpty(Queue *); Boolean QueueFull(Queue *); Data Structure 2014 R. Wei 12
13 void CreateQueue(Queue *q) q->count = 0; q->front = 0; q->rear = -1; } void Append(QueueEntry x,queue *q) if(queuefull(q)) Error("Cannot append an entry to a full queue."); else q->count++; q->rear = (q->rear +1)%MAXQUEUE; q->entry[q->rear)]=x; } } Data Structure 2014 R. Wei 13
14 void Serve(QueueEntry *x,queue *q) if(queueempty(q)) Error("Can t serve from a an empty queue."); else q->cont--; *x = q->entry[q->front]; q->front=(q->front+1)%maxqueue; } } Data Structure 2014 R. Wei 14
15 Boolean QueueEmpty(Queue *q) return q->count <=0; } Boolean QueueFull(Queue *q) return q->cout >=MAXQUEUE; } int QueueSize(Queue *q) return q->count; } Data Structure 2014 R. Wei 15
16 3.3 Computer simulation Simulation is the use of one system to imitate the behavior of another system, when it is too expensive or dangerous to experiment with the real system. A computer simulation uses the steps of a program to imitate the behavior of a system under study. We study a simple but useful computer simulation which concentrates on queues as its basic data structure. These simulations imitate the behavior of systems in which there are queues of objects waiting to be served by various processes. Data Structure 2014 R. Wei 16
17 Example Consider a small but busy airport with only one runway: In each unit of time, one plane can land or one plane can take off, but not both. Planes arrive ready to land or to take off at random times. It is better to keep a plane waiting on the ground than in the air, so the airport allows a plane to take off only if there are no planes waiting to land. Data Structure 2014 R. Wei 17
18 We will use two queues: takeoff and landing in the simulation. A plane is appended to a queue at random with certain probability in a unit time. The simulation runs for many units of time. It starts for curtime from 1 to a variable endtime. We will use a function RandomNumber() to output a random number between 0 and INT MAX with given average, which will denote the number of planes at a unit of time. Data Structure 2014 R. Wei 18
19 Outline of the simulation program: Settings: Queue landing, takeoff; Queue *pl = &landing; Queue *pt = &takeoff; Plane plane; //abstrat of a plane int curtime; //current time unit int endtime; //total number of time units to run Initialization: CreateQueue(pl); CreateQueue(pt); Data Structure 2014 R. Wei 19
20 Simulate queue landing at a unit of time: for(i = 1; i <= RandomNumber();i++) NewPlane(&plane); //new planes arrive if (QueueFull(pl) Refuse(plane); else Append(plane,pl); } Simulation of queue takeoff at a unit of time is similar. Data Structure 2014 R. Wei 20
21 Simulation of the control: if(!queueempty(pl)) Serve(&plane,pl); Land(plane); } else if(!queueempty(pt)) Serve(&plane,pt); } else Idle(); Data Structure 2014 R. Wei 21
22 Now we consider some details. First, the queues we used are queue of planes. #define MAXQUEUE 5 //use a small value for testing typedef enum action ARRIVE, DEPART} Action; typedef struct plane int id; //id number of plane int tm; //time of arrival in queue } Plane; typedef Plane QueueEntry; typedef struct queue int count; //number of planes in the queue int front; int rear; QueueEntry entry[maxqueue]; } Queue; Data Structure 2014 R. Wei 22
23 The purpose of the simulation is to obtain some data about the airport. So we need to record the number of planes, the waiting time, the numbers of departure and arriving planes, etc. The simulation also wants to know the different data in different settings of the probability of arriving planes and departing planes. Data Structure 2014 R. Wei 23
24 /*NewPlane: make a new record for a plan, update nplanes. Pre: None. Post: Makes a new plane and update nplanes.*/ void NewPlane(Plane *p,int *nplanes,int curtime,action kind) (*nplanes)++; p->id=*nplanes; p->tm=curtime; switch(kind) case ARRIVE: printf(" Plane %3d ready to land.\n",*nplanes); break; case DEPART: printf(" Plane %3d ready to take off.\n",*nplanes); break; } } Data Structure 2014 R. Wei 24
25 /*Refuse: processes a plan when the queueis full. Pre: None. Post: processes a plane requesting runway, but queue is full*/ void Refuse(Plane p, int *nrefuse,action kind) switch(kind) case ARRIVE: printf(" Plane %3d directed to another airport.\n",p.id); break; case DEPART: printf(" Plane %3d told to try later.\n".p.id); break; } (*nrefuse)++; } Data Structure 2014 R. Wei 25
26 /*Land: process a plane that is actually landing. Pre: None. Post: Precesses a plane p that is landing.*/ void Land(Plane p,int curtime,int *nland,int *landwait) int wait; wait = curtime - p.tm; printf("%3d: Plane %3d landed; in queue %d units. \n",curtime,p.id,wait); (*nland)++; *landwait+= wait; } The function Fly is similar. Data Structure 2014 R. Wei 26
27 /* Idle: undate variables for idle runway. Pre: None. Post: Update variables for a time unit when the runway is idle. */ void Idel(int curtime,int *idletime) printf("%3d: Runway is idel.\n",curtime); (*idletime)++; } Data Structure 2014 R. Wei 27
28 Two functions: Start and Conclude are used to initialize and conclude statistical data for the simulation. /*Start: print messages and initialize the parameters. Pre:None. Post: Asks user for responses and initializes all variables specified as parameters. Uses: UserSaysYes.*/ void Start(int *endtime,double *expectarrive, double *expectdepart) Data Structure 2014 R. Wei 28
29 /*Conclude: write out statistics and conclude simulation. Pre: None. Post: Writes out all the statistics and concludes the simulation.*/ void Conclude(int nplanes, int nland, int ntakeoff, int nrefuse, int landwait, int takeoffwait, int idletime,int endtime, Queue *pt, Queue *pl) We omitted the details of these two functions. The details of creating pseudo-random numbers are omitted. Data Structure 2014 R. Wei 29
30 Implementation using dynamic memory // Queue ADT Type Defintions typedef struct node void* dataptr; struct node* next; } QUEUE_NODE; typedef struct QUEUE_NODE* front; QUEUE_NODE* rear; int count; } QUEUE; Data Structure 2014 R. Wei 30
31 QUEUE* createqueue (void) // Local Definitions QUEUE* queue; // Statements queue = (QUEUE*) malloc (sizeof (QUEUE)); if (queue) queue->front = NULL; queue->rear = NULL; queue->count = 0; } // if return queue; } // createqueue Data Structure 2014 R. Wei 31
32 bool enqueue (QUEUE* queue, void* itemptr) QUEUE_NODE* newptr; if (!(newptr = (QUEUE_NODE*)malloc(sizeof(QUEUE_NODE)))) return false; newptr->dataptr = itemptr; newptr->next = NULL; if (queue->count == 0) queue->front = newptr; else queue->rear->next = newptr; (queue->count)++; queue->rear = newptr; return true; } // enqueue Data Structure 2014 R. Wei 32
33 bool dequeue (QUEUE* queue, void** itemptr) QUEUE_NODE* deleteloc; if (!queue->count) return false; *itemptr = queue->front->dataptr; deleteloc = queue->front; if (queue->count == 1) queue->rear = queue->front = NULL; else queue->front = queue->front->next; (queue->count)--; free (deleteloc); return true; } // dequeue Data Structure 2014 R. Wei 33
34 bool queuefront (QUEUE* queue, void** itemptr) // Statements if (!queue->count) return false; else *itemptr = queue->front->dataptr; return true; } // else } // queuefront Data Structure 2014 R. Wei 34
35 bool queuerear (QUEUE* queue, void** itemptr) // Statements if (!queue->count) return true; else *itemptr = queue->rear->dataptr; return false; } // else } // queuerear Data Structure 2014 R. Wei 35
36 bool emptyqueue (QUEUE* queue) // Statements return (queue->count == 0); } // emptyqueue Data Structure 2014 R. Wei 36
37 bool fullqueue (QUEUE* queue) // Local Definitions * QUEUE_NODE* temp; // Statements temp = (QUEUE_NODE*)malloc(sizeof(*(queue->rear))); if (temp) free (temp); return true; } // if // Heap full return false; } // fullqueue Data Structure 2014 R. Wei 37
38 int queuecount(queue* queue) // Statements return queue->count; } // queuecount Data Structure 2014 R. Wei 38
39 QUEUE* destroyqueue (QUEUE* queue) QUEUE_NODE* deleteptr; if (queue) while (queue->front!= NULL) free (queue->front->dataptr); deleteptr = queue->front; queue->front = queue->front->next; free (deleteptr); } // while free (queue); } // if return NULL; } // destroyqueue Data Structure 2014 R. Wei 39
40 Application: Polynomial arithmetic Using a reverse Polish calculator to do polynomial arithmetics. basic idea is using a stack. The basic idea of reverse Polish calculator is to input operands first and input operation. For example: if we want to calculate (a + b) (c + d), then the inputs are: a b + c d +. If we want to calculate a (b + c), then the inputs are: b c + a. To do the calculations, push the operands to a stack. If an operation is input, then pop out two operands and do the operation and then push the result to the stack. When = is input, pop out the result. Data Structure 2014 R. Wei 40
41 The outline of the program is quite simple: mainly use ReadCommand to get the inputs and use DoCommand to do the calculation. To represent polynomials, we use a queues. For a polynomial 3x 5 2x 3 + x 2 + 4, we can use a queue of size 4 to represent it. Each item of the queue represent a term. Data Structure 2014 R. Wei 41
42 typedef struct term double coef; int exp; } Term; The term 2x 3 can be stored as: Term *newterm; newterm->coef = -2.0; newterm->exp = 3; Data Structure 2014 R. Wei 42
Queues. Manolis Koubarakis. Data Structures and Programming Techniques
Queues Manolis Koubarakis 1 The ADT Queue A queue Q of items of type T is a sequence of items of type T on which the following operations are defined: Initialize the queue to the empty queue. Determine
Linked Lists Linked Lists, Queues, and Stacks
Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points
St S a t ck a ck nd Qu Q eue 1
Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines
Stacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Queue The ADT Queue is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit addition
DATA STRUCTURE - QUEUE
DATA STRUCTURE - QUEUE http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm Copyright tutorialspoint.com Queue is an abstract data structure, somewhat similar to stack. In contrast to
CS 2412 Data Structures. Chapter 2 Stacks and recursion
CS 2412 Data Structures Chapter 2 Stacks and recursion 1 2.1 Stacks A stack is a data structure in which all insertions and deletions of entries are made at one end, called top of the stack. Examples:
This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues 1. 2004 Goodrich, Tamassia
This lecture Abstract data types Stacks Queues ADTs, Stacks, Queues 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations
Common Data Structures
Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees
Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s
Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number
Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic
Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!
Programming with Data Structures
Programming with Data Structures CMPSCI 187 Spring 2016 Please find a seat Try to sit close to the center (the room will be pretty full!) Turn off or silence your mobile phone Turn off your other internet-enabled
BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering
BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security & BSc. (Hons.) Software Engineering Cohort: BIS/05/FT BCNS/05/FT BSE/05/FT Examinations for 2005-2006 / Semester
What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation
Stacks and Queues What is a Stack? Stores a set of elements in a particular order Accessed in Last-In In-First-Out (LIFO) fashion Real life examples: Pile of books PEZ dispenser Cup trays in cafeteria
Module 2 Stacks and Queues: Abstract Data Types
Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which
1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++
Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The
Introduction to Data Structures and Algorithms
Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures
Application of Stacks: Postfix Expressions Calculator (cont d.)
Application of Stacks: Postfix Expressions Calculator (cont d.) Postfix expression: 6 3 + 2 * = FIGURE 7-15 Evaluating the postfix expression: 6 3 + 2 * = Data Structures Using C++ 2E 1 Application of
QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q
QUEUES A queue is simply a waiting line that grows by adding elements to its end and shrinks by removing elements from the. Compared to stack, it reflects the more commonly used maxim in real-world, namely,
Basic Data Structures and Algorithms
Tutorial 3 Basic Data Structures and Algorithms THINGS TO LOOK FOR 3.0 INTRODUCTION 3.1 Array Based Containers Definition and uses of containers. Array and list based containers. Designing and building
Linked Lists, Stacks, Queues, Deques. It s time for a chainge!
Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems
PES Institute of Technology-BSC QUESTION BANK
PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions
CSE 211: Data Structures Lecture Notes VII
CSE 211: Data Structures Lecture Notes VII LINKED LISTS In the previous lectures we have seen the representation of ordered lists using an array and sequential mapping. These representations had the property
STACKS,QUEUES, AND LINKED LISTS
STACKS,QUEUES, AND LINKED LISTS Stacks Queues Linked Lists Double-Ended Queues Case Study: A Stock Analysis Applet 1 Stacks Astack is a container of objects that are inserted and removed according to the
Lecture Notes on Stacks & Queues
Lecture Notes on Stacks & Queues 15-122: Principles of Imperative Computation Frank Pfenning, André Platzer, Rob Simmons Lecture 9 February 12, 2013 1 Introduction In this lecture we introduce queues and
Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta
Linear DT-1: Restricted Lists Stacks, Queues tul Gupta Restricted Lists Stack Queue Circular queue Priority queue General Lists rrays Linked list Circular list Doubly linked list Linear DTs 1 Stacks Using
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A
CmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is
10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a
List, Stack and Queue. Tom Chao Zhou CSC2100B Data Structures Tutorial 3
List, Stack and Queue Tom Chao Zhou CSC2100B Data Structures Tutorial 3 Outline Structure Linked List Overview Implementation Stack Overview Implementation Queue Overview Implementation Structure A collection
Universidad Carlos III de Madrid
Universidad Carlos III de Madrid Algorithms and Data Structures (ADS) Bachelor in Informatics Engineering Computer Science Department Lists, Stacks and Queues. Authors: Isabel Segura Bedmar April 2011
Questions 1 through 25 are worth 2 points each. Choose one best answer for each.
Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in
Big O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.
Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit lim n f ( n) g ( n ) What does it
Algorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction
Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know
EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE)
EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE) UNIT I LINEAR STRUCTURES Abstract Data Types (ADT) List ADT array-based implementation linked list implementation cursor-based linked lists
Queues and Stacks. Atul Prakash Downey: Chapter 15 and 16
Queues and Stacks Atul Prakash Downey: Chapter 15 and 16 Queues Queues occur in real life a lot. Queues at checkout Queues in banks In software systems: Queue of requests at a web servers Properties of
Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010
Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement
1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: 15.1-15.3. Data Structures
1.00 Lecture 35 Data Structures: Introduction Stacks, Queues Reading for next time: Big Java: 15.1-15.3 Data Structures Set of reusable classes used in algorithms, simulations, operating systems, applications
Data Structures Using C++ 2E. Chapter 5 Linked Lists
Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given
Data Structures, Practice Homework 2, with Solutions (not to be handed in)
Data Structures, Practice Homework 2, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 7, Exercise 4. Consider a function int Queue::getNumberOfElements() const that returns the number
Chapter 3: Restricted Structures Page 1
Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both
7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
Data Structures and Algorithms Stacks and Queues
Data Structures and Algorithms Stacks and Queues Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/23 6-0: Stacks and
Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1
Stacks (and Queues) 1 Stacks Stack: what is it? ADT Applications Implementation(s) 2 CSCU9A3 1 Stacks and ueues A stack is a very important data structure in computing science. A stack is a seuence of
Data Structures and Algorithms
Data Structures and Algorithms Lecture 4 2016 Stacks and... 1/28 1 2 Circular Linked 3 Queue Syntax and Functions in C++ 4 Stacks and... 2/28 FIFO and LIFO Outline Data structures can be specialized versions
1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.
1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated
Data Structures and Data Manipulation
Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval
Introduction to Data Structures
Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate
Analysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
Sequential Data Structures
Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year
Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!
ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting
Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1
Data Structure By Ajay Raiyani Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1 Linked List 4 Singly Linked List...4 Doubly Linked List...7 Explain Doubly Linked list: -...7 Circular Singly Linked
Cpt S 223. School of EECS, WSU
Abstract Data Types 1 Topics Abstract Data Types (ADTs) Some basic ADTs: Lists Stacks Queues 2 Primitive Data Type vs. Abstract Data Types Primitive DT: ADT: programmer progra ammer Interface (API) e.g.,
Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists
Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse
Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;
50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)
Data Structures and Algorithms V22.0102. Otávio Braga
Data Structures and Algorithms V22.0102 Otávio Braga We use a stack When an operand is read, output it When an operator is read Pop until the top of the stack has an element of lower precedence Then push
I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1
General Computer Architecture I/O Management COMP755 Advanced Operating Systems Goals for I/O Users should access all devices in a uniform manner. Devices should be named in a uniform manner. The OS, without
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Registration We have 180 students registered and others who want to get in. If you re thinking of dropping
MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------
=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com
22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department http://www.cs.uiowa.edu/~hzhang/c31/
22c:31 Algorithms Ch3: Data Structures Hantao Zhang Computer Science Department http://www.cs.uiowa.edu/~hzhang/c31/ Linear Data Structures Now we can now explore some convenient techniques for organizing
Outline. The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack. Stacks 2
Stacks Outline The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack Stacks 2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure
1 Abstract Data Types Information Hiding
1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content
Abstract Data Types. Chapter 2
Chapter 2 Abstract Data Types The second idea at the core of computer science, along with algorithms, is data. In a modern computer, data consists fundamentally of binary bits, but meaningful data is organized
Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap
Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap Singly linked list (1) Data about exam results are stored into a singly linked list. Each list
DATA STRUCTURES USING C
DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give
Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1
Stack & Queue Explain Array in detail One Dimensional Array Simplest data structure that makes use of computed address to locate its elements is the onedimensional array or vector; number of memory locations
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015
Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may
Data Structures, Practice Homework 3, with Solutions (not to be handed in)
Data Structures, Practice Homework 3, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 9, Exercise 1: What is the order of each of the following tasks in the worst case? (a) Computing
Lecture 12 Doubly Linked Lists (with Recursion)
Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)
Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.
Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles
14 Stacks, Queues, And Linked Lists
14-1 Java Au Naturel by William C. Jones 14-1 14 Stacks, Queues, And Linked Lists Overview This chapter requires that you have a solid understanding of arrays (Chapter Seven) and have studied Exceptions
Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson
Outline Computer Science 1 Stacks Mike Jacobson Department of Computer Science University of Calgary Lecture #12 1 2 Applications Array-Based Linked List-Based 4 Additional Information Mike Jacobson (University
ADTs,, Arrays, Linked Lists
1 ADTs,, Arrays, Linked Lists Outline and Required Reading: ADTs ( 2.1.2) Arrays ( 1.5) Linked Lists ( 4.3.1, 4.3.2) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Abstract Data Type (ADT) 2 abstract
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Binary Heap Algorithms
CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks [email protected] 2005 2009 Glenn G. Chappell
For the next three questions, consider the class declaration: Member function implementations put inline to save space.
Instructions: This homework assignment focuses on basic facts regarding classes in C++. Submit your answers via the Curator System as OQ4. For the next three questions, consider the class declaration:
Illustration 1: Diagram of program function and data flow
The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline
Queue Implementations
Queue Implementations as double 1 2 as double MCS 360 Lecture 17 Introduction to Data Structures Jan Verschelde, 1 October 2010 Queue Implementations as double 1 2 as double a circular as double A can
C Dynamic Data Structures. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell
C Dynamic Data Structures University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell Data Structures A data structure is a particular organization of data in memory. We want to
5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.
1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The
DATA STRUCTURE - STACK
DATA STRUCTURE - STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming
STACK Data Structure:
STACK Data Structure: Data Structures using C Chapter-3 STACK AND QUEUE A stack is an ordered list in which insertions and deletions are made at one end called the top. o If we add the elements A, B, C,
What Is Recursion? 5/12/10 1. CMPSC 24: Lecture 13 Recursion. Lecture Plan. Divyakant Agrawal Department of Computer Science UC Santa Barbara
CMPSC 24: Lecture 13 Recursion Divyakant Agrawal Department of Computer Science UC Santa Barbara 5/12/10 1 Lecture Plan Recursion General structure of recursive soluions Why do recursive soluions terminate?
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double
! stack, queue, priority queue, dictionary, sequence, set e.g., a Stack is a list implements a LIFO policy on additions/deletions.
Abstract Data Types and Data Structures Often, these terms are used as synonyms. But it s better to think of them this way: ADTs and Data Structures An Abstract Data Type (ADT) represents a particular
Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C
Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate
Data Structures CSC212 (1) Dr Muhammad Hussain Lecture - Binary Search Tree ADT
(1) Binary Search Tree ADT 56 26 200 18 28 190 213 12 24 27 (2) Binary Search Tree ADT (BST) It is a binary tree with the following properties 1. with each node associate a key 2. the key of each node
Data Structures Using C++
Data Structures Using C++ 1.1 Introduction Data structure is an implementation of an abstract data type having its own set of data elements along with functions to perform operations on that data. Arrays
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
Data Structures UNIT III. Model Question Answer
Data Structures UNIT III Model Question Answer Q.1. Define Stack? What are the different primitive operations on Stack? Ans: Stack: A stack is a linear structure in which items may be added or removed
A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
Chapter 5 Instructor's Manual
The Essentials of Computer Organization and Architecture Linda Null and Julia Lobur Jones and Bartlett Publishers, 2003 Chapter 5 Instructor's Manual Chapter Objectives Chapter 5, A Closer Look at Instruction
Intel EP80579 Software for Security Applications on Intel QuickAssist Technology Cryptographic API Reference
Intel EP80579 Software for Security Applications on Intel QuickAssist Technology Cryptographic API Reference Automatically generated from sources, May 19, 2009. Reference Number: 320184, Revision -003
Stacks and queues. Algorithms and Data Structures, Fall 2011. Rasmus Pagh. Based on slides by Kevin Wayne, Princeton
Algorithms and Data Structures, Fall 2011 Stacks and queues Rasmus Pagh Based on slides by Kevin Wayne, Princeton Algorithms, 4 th Edition Robert Sedgewick and Kevin Wayne Copyright 2002 2011 Stacks and
