# Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

Save this PDF as:

Size: px
Start display at page:

Download "Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta"

## Transcription

1 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

2 Stacks Using Stacks: Checking Expression Validity Consider the following expression [a + b *({c/d(1-n) + e/f (1+n))/(g sqrt[(b**2) 4*a*c]/2)] 2

3 Using Stacks: Checking Expression Validity bool ckeck_validity(char[ ] exp){ char next_char, popped_char; stack S; bool valid = true; while (not_empty(exp)) { next_char = get_next(exp); if ((next_char == ( ) or (next_char == {) or (next_char == [ )) then push (S, next_char); if ((next_char == ) ) or (next_char == ) or (next_char == ] )) then { popped_char = pop (S); if (next_char <> popped_char) return (valid = false); If (not_empty(s)) then valid = false; return valid; Stack Linear LIFO organization n attribute topalways pointing to the most recently inserted data item Basic operations void push(x, S) : Insert element x into S item pop(s) : Return the last element inserted into S boolean isstackempty(s): Return yes if S is empty 3

4 pplications of Stacks Direct applications Delimiter matching Undo sequence in a text editor Chain of method calls in the Java Virtual Machine Expression evaluations Indirect applications uxiliary data structure for algorithms Component of other data structures 7 Stack: n rray Implementation createstack(s): Define an array S for some fixed size N, top -1 S push(x,s): if top = N-1 then error else top top + 1 S[top] x False isstackempty(s): return (top < 0) pop(s): if isstackempty() then error else item S[top] top top 1 X return (item) top -1 X 4

5 Stack nimation: rray Implementation createstack() push (X, S) push (Y, S) push (Z, S) pop (S) istackempty (S) push (, S) push (B, S) push (C, S) push (D, S) push (E, S) push (F, S) Stack is FULL False Z top -1 E D C B Z Y X S Stack: Pointer Implementation Pointer facilitate dynamic implementation of a data structure Data is organized in a dynamic structure comprising of nodes where each node is identified by a reference (pointer) contains a data element may points to next node/null p p.element p.next 5

6 Stack: Pointer Implementation createstack(s): Define a pointer top, top null push(x,s): n = create new node n.element x n.next top top n isstackempty (S): return (top == null) pop(s): if isstackempty() then error else e top.element top top.next return (e) e n top e False X Stack nimation: Pointer Implementation createstack(s) push (X, S) push (Y, S) push (Z, S) pop (S) istackempty (S) push (, S) push (B, S) push (C, S) push (D, S) push (E, S) push (F, S) top False Z Y X e e 6

7 Stack: The running time createstack(s): Define a pointer top, top null push(x,s): n = create new node n.element x n.next top top n Each operation takes O(1) time isstackempty (S): return (top == null) pop(s): if isstackempty() then error else e top.element top top.next return (e) Stack: C implementation using rray #define MX 10 struct stack { int arr[mx]; int top; STCK; void createstack(stck *); int stackempty( STCK *) intstackfull( STCK *) void push (STCK *, intitem); intpop (STCK *); intstackfull( STCK *s) { if ( s -> top == MX -1 ) return (1); else return (0); void createstack(stck * s ) { s -> top = -1; void push ( STCK *s, intitem ){ if ( stackfull(s)) { printf( "\nstackis full." ); return; s -> top++ ; s -> arr[s ->top] = item; int stackempty( STCK *s) { if ( s -> top == -1 ) return (1); else return (0); intpop( structstack *s ) { int item; if ( stackempty(s)) { printf( "\nstackis empty." ); return NULL; item = s -> arr[s -> top]; s -> top--; return item; 7

8 Stack: C implementation using Pointer struct node { intdata ; struct node *link ; ; void createstack(struct node ** ) void push ( structnode **, int); intpop ( structnode ** ); void delstack( structnode ** ); Int stackempty( struct node **); int stackempty( struct node **tos) { return ( *tos== NULL ); void createstack(structnode ** top ) { top = NULL; void push ( structnode **top, intitem ){ struct node *temp; temp = (struct node*) malloc(sizeof(struct node )); if ( temp == NULL ) printf( "\nstackis full." ); temp -> data = item; temp -> link = *top; *top = temp; intpop ( structnode **top ) { struct node *temp; int item; if (stackempty(top)) { printf( "\nstackis empty." ); return 0 ; temp = *top; item = temp -> data; *top = ( *top ) -> link; free ( temp ); return item; Queue Linear FIFO organization n attribute points to the place the next data item to be inserted n attribute front points to the next data item to be removed Basic operations void enqueue(x,q) :Insert element x into Q item dequeue(q) :Return the last element inserted into Q boolean isqueueempty(q): Return yes if Q is empty 8

9 Queue void enqueue(x, Q) :Insert lastelement x into Q item dequeue(q) :Delete the firstelement in Q boolean isqueueempty?(q): Return yes if Q is empty item front(q): Return the first element in Q int size(q): Return the number of elements in the Q Queue make-queue(): Initialize a Q Queue: rray Implementation X Y front makequeue(q) enqueue(x, Q) enqueue(y, Q) enqueue(z, Q) dequeue(q) isqueueempty( Q) dequeue(q) enqueue(, Q) enqueue(b, Q) 9

10 Queue: rray Implementation front Empty Queue? front == Circular Queue: rray Implementation front Empty Queue? front == Full Queue? front == (+1) mod N

11 Circular Queues: Types of rray Implementations front is always at first position n array with two indices always increasing circular array with frontand and one position is left vacant circular array with two indices and a boolean variable circular array with two indices and a count (size) variable Special values for array indices Circular rray with size() function isqueueempty(q): return (front == ) front(q): if (isqueueempty(q)) then error else return [front] pop(q): if (isqueueempty(q)) then error else e [front] front (front + 1) mod N return (e) size(q): if ( >= front) then return (-front+1) else return (N-(front-)) enqueue(x,q): if size(q) == N then error else [] x (+1) mod N dequeue(q): if (isqueueempty?(q)) then error else e [front] front (front + 1) mod N return (e) 11

12 Queue: Pointer Implementation fron t size=3 B C enqueue(d,q) new p D Implementation with lists fron t size=3 B C D enqueue(d,q) 12

13 Double Ended Queue (Deque) insertfront(x,d) :Insert x as the first in D dequeue(d) :Delete the first element of D enqueue(x,d):insert x as the last in D removelast(d): Delete the last element of D Size(D) isqueueempty?(d) make-deque() Implementation of Dequewith Doubly Linked Lists We use two sentinels (dummy nodes) here to make the code simpler front size=2 B x.prev x x.next x.element 13

14 Empty Deque? front size=0 front.next == &&.prev == front Insert Element in the Deque front size=1 insertfront(b,d): n = new node n.element B n.next front.next (front.next).prev n front.next n n.prev front size size

15 n front B insertfront(b,d): n = new node n.element B n.next front.next (front.next).prev n front.next n n.prev front size size + 1 size=1 n front B insertfront(b,d): n = new node n.element B n.next front.next (front.next).prev n front.next n n.prev front size size + 1 size=1 15

16 n front B insertfront(b,d): n = new node n.element B n.next front.next (front.next).prev n front.next n n.prev front size size + 1 size=1 n front B insertfront(b,d): n = new node n.element B n.next front.next (front.next).prev n front.next n n.prev front size size + 1 size=2 16

17 Restricted Linear DT: Summary Two important forms of linear restricted DT are Stacks and Queues Stack is LIFO and Queue is FIFO ll operations are O(1) Typically not used as search data structures Where to use them? 17

### 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,

### 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

### 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

### 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

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

### Stacks & Queues. Data structures and Algorithms

Stacks & Queues Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004) Outline

### csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues Summary Topics stacks and queues as abstract data types implementations arrays linked lists analysis and comparison application: searching with stacks and queues

### Data Structures and Algorithms

Data Structures and Algorithms CS245-2016S-04 Stacks and Queues David Galles Department of Computer Science University of San Francisco 04-0: Abstract Data Types An Abstract Data Type is a definition of

### 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, Queues and Linked Lists

Stacks, Queues and Linked Lists Adnan Aziz 1 Dynamic sets CLRS Part III, page 197 In mathematics, a set is a well-defined collection of elements (elements could be numbers, functions, geometric shapes);

### 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

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

### Data Structures. Topic #4

Topic #4 Today s Agenda Stack and Queue ADTs What are they Like Ordered Lists, are position oriented Use of Data Structures for Stacks and Queues arrays (statically & dynamically allocated) linear linked

### 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

### 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

### 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

### 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

### TIE-20106 1 TIE-20106 2

TIE-20106 1 1 List structures In this chapter, a few simple data structures (stack and queue) that can be implemented with arrays and/or lists are covered. Two more complex structures based on lists are

### UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE

STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia

### 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

### \Mankinds's progress is measured by the number of. Elementary data structures such as stacks, queues,

Elementary Data Structures \Mankinds's progress is measured by the number of things we can do without thinking." Elementary data structures such as stacks, queues, lists, and heaps will be the \of-the-shelf"

### Introduction to Stacks

Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack. What is a Stack? Stack is a data structure in which data is added

### 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!

### Announcements. FINAL EXAM Monday May 21, 1:30pm Review Session. Wednesday May 16, 7-9pm

Announcements FINAL EXAM Monday May 21, 1:30pm Review Session Wednesday May 16, 7-9pm 1 Recitation 12 Root Finding, Sorting, Stacks, Queues 2 Outline Linked Lists Sorting Queues 3 Object References Let

### 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

### 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,

### 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

### 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

### 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

### 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

### 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

Arrays, Singly-Linked Lists, Stacks, Queues, Doubly-Linked Lists, Deques Slide Set 5: Learning Goals Differentiate an abstraction from an implementation. Define and give examples of problems that can be

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### 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

### 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

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

### Data Structures and Algorithms(3)

Ming Zhang Data Structures and Algorithms Data Structures and Algorithms(3) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh

### 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

### 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 Structure. Lecture 3

Data Structure Lecture 3 Data Structure Formally define Data structure as: DS describes not only set of objects but the ways they are related, the set of operations which may be applied to the elements

### 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

### 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

### 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

### 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

### Algorithms and Data Structures

Basic Data Structures Page 1 BFH-TI: Softwareschule Schweiz Basic Data Structures Dr. CAS SD01 Basic Data Structures Page 2 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing

### 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

### 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

### 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

### Vector ADT. A Vector stores a list of elements: Access via rank/index.

Vector ADT A Vector stores a list of elements: Access via rank/index. Accessor methods: elementatrank(r), Update methods: replaceatrank(r, o), insertatrank(r, o), removeatrank(r) Generic methods: size(),

### C++ Introduction to class and data abstraction

C++ Introduction to class and data abstraction 1 Data abstraction A data abstraction is a simplified view of an object by specifying what can be done with the object while hiding unnecessary details In

### 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

### Algorithms and Data Structures Written Exam Proposed SOLUTION

Algorithms and Data Structures Written Exam Proposed SOLUTION 2005-01-07 from 09:00 to 13:00 Allowed tools: A standard calculator. Grading criteria: You can get at most 30 points. For an E, 15 points are

### 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

### CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II - CSE III - SEMESTER ACADEMIC YEAR:

CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II - CSE III - SEMESTER ACADEMIC YEAR: 2012-2013 SCHOOL OF COMPUTER SCIENCE & ENGINEERING SRM UNIVERSITY, SRM NAGAR, KATTANKULATHUR-603203.

### 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

### 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

### 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:

### 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.,

### CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Nicki Dell Spring 2014

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Nicki Dell Spring 2014 Registration We have 140 students registered and 140+ on the wait list! If you re thinking of

### 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

### Data Structures and Algorithms C++ Implementation

BK TP.HCM Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering BK TP.HCM Data Structures and Algorithms C++ Implementation Huỳnh Tấn Đạt Email: htdat@cse.hcmut.edu.vn Home

### 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

### 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

### 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

### The Queue Data Structure in C++ By Eric Suh

The Queue Data Structure in C++ By Eric Suh http://www.cprogramming.com/tutorial/computersciencetheory/queue.html Queues are data structures that, like the stack, have restrictions on where you can add

### 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

### BM267 - Introduction to Data Structures

BM267 - Introduction to Data Structures 3. Elementary Data Structures Ankara University Computer Engineering Department BLM267 1 Objectives Learn about elementary data structures - Data structures that

### ! 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

### Data Structures. value. key. 5 Alpha. 3 Beta. 7 Gamma

Data Structures key value 5 Alpha 10 2 7 5 1 4 9 3 6 8 3 Beta 7 Gamma Sequence Associative e.g., C-Arrays, std::vector, std::deque, std::list e.g., C-Arrays, std::map, std::set, std::unordered_map Data

### System Software Prof. Dr. H. Mössenböck

System Software Prof. Dr. H. Mössenböck 1. Memory Management 2. Garbage Collection 3. Linkers and Loaders 4. Debuggers 5. Text Editors Marks obtained by end-term exam http://ssw.jku.at/misc/ssw/ 1. Memory

### 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

### 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

### Queue ADT. March 16, 2000

Queue ADT March 6, 2000 The Queue ADT Queue represent another form of linear data structure. As in the case of the list, the idea of a queue is to represent sequences of elements, all having the same type.

### 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

### Lecture 6b Linked List Variations. Similar but not the same

Lecture 6b Linked List Variations Similar but not the same Linked List Variations: Overview The linked list implementation used in List ADT is known as Singly (Single) Linked List Each node has one pointer

### 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

LINKED DATA STRUCTURES 1 Linked Lists A linked list is a structure in which objects refer to the same kind of object, and where: the objects, called nodes, are linked in a linear sequence. we keep a reference

### Data Structures and Algorithms. Lab 1. Hands on Data Structures Using C++ Stacks and Queues

Data Structures and Algorithms Lab 1 Hands on Data Structures Using C++ Stacks and Queues Dr. Rabie A. Ramadan Notes: Students must read this document before the lab and make their code ready for compilation.

### Monitors, Java, Threads and Processes

Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept

### 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

### Algorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser

Algorithms and Data Structures Stack, Queues, and Applications Ulf Leser Content of this Lecture Stacks and Queues Tree Traversal Towers of Hanoi Ulf Leser: Alg&DS, Summer semester 2011 2 Stacks and Queues

### 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

### University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Fall 2007 7p-9p, Thursday, October 4 Name: NetID: Lab Section

Linked Lists and Iterators Chapter 4 Click to proceed How To View This Presentation This presentation is arranged in outline format. To view the slides in proper order For each slide Read the entire slide

### Collections & Data Structures. CS 3: Computer Programming in Java

Collections & Data Structures CS 3: Computer Programming in Java Objectives The concept of a collection Separating the interface from the implementation Dynamic data structures Linked lists Queues and

### Chapter 13. Pointers and Linked Lists

Chapter 13 Pointers and Linked Lists Overview 13.1 Nodes and Linked Lists 13.2 Stacks and Queues Slide 13-2 13.1 Nodes and Linked Lists Nodes and Linked Lists n A linked list is a list that can grow and

### Chapter 7: Queues and Deques

Chapter 7: Queues and Deques After the stack, the next simplest data abstraction is the queue. As with the stack, the queue can be visualized with many examples you are already familiar with from everyday

### 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)

### 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

### Pallab Dasgupta. Linked Lists CS10001: Programming & Data Structures. Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Linked Lists CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Arrays: pluses and minuses + Fast element access. -- Impossible

### International Journal Of Engineering Research & Management Technology

International Journal Of Engineering Research & Management Technology ISSN: 2348-4039 September- 2014 Volume 1, Issue-5 Dynamic Implementation Using Linked List Karuna Department of Information and Technology

### 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

### 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)

### CHAPTER 4 ESSENTIAL DATA STRUCTRURES

CHAPTER 4 ESSENTIAL DATA STRUCTURES 72 CHAPTER 4 ESSENTIAL DATA STRUCTRURES In every algorithm, there is a need to store data. Ranging from storing a single value in a single variable, to more complex

### Comp 245 Data Structures. Stacks

Comp 245 Data Structures Stacks What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO random access to other elements within the stack An

### EE Embedded Systems Design. Lessons Real Time Operating Systems

EE4800-03 Embedded Systems Design Lessons 19-22 Real Time Operating Systems Revised: Dec 15, 2003 1 Overview RTOS Concepts Data structures Dynamic memory allocation Task and Task Control Blocks RTOS tracking

### Data Structures Fibonacci Heaps, Amortized Analysis

Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

### 4.3 Stacks and Queues. Pushdown Stacks. Data Structures and Data Types. Collections

Data Structures and Data Types 4.3 Stacks and Queues Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack,