Computer Science BS Degree - Data Structures (I2206) Abstract Data Types (ADT)
|
|
- Felix Hines
- 5 years ago
- Views:
Transcription
1 Abstract Data Types (ADT) 70
2 Hierarchy of types Each type is implemented in terms if the types lower in the hierarchy Level 0 Bit Byte Word Level 1 Integer Real Char Boolean Pointer Level 2 Array Record Level 3 Tree List Stack Set Graph Data types Data Structures Abstract Data Types is composed of 71
3 Introduction Ideal: to have a high level language with all abstract data types built in, in the same way that arrays and records are built into C. Difficulty: for most abstract data types, there is no unique and efficient implementation. It is left to the programmer to define abstract data types and provide implementation for them in terms of the hierarchy of types of a language (such as C). 72
4 Introduction Once an ADT is specified and implemented, it can be used like any other built-in type with no reference to its particular implementation. To specify an ADT: Never think about implementation Think about the types applicable operations Think about formal properties linking these operations 73
5 Stacks 74
6 What is a Stack? A stack is a linear ADT. The order in which data arrives is important Definition: A stack is an ordered list in which insertion and deletion are done at one end (called top). The last element inserted is the first one to be deleted. Last In First Out (LIFO) or First In Last Out (FILO). 75
7 What is a Stack? push: insert an element in a stack pop: remove an element in a stack Underflow: pop out an empty stack Push A Push B Push C Push D Pop Push E top DE C B A 76
8 Stack ADT The following operations make a stack an ADT. Main stack operations: Create_stack: Create of an empty stack. Push: Insert data onto stack. Pop: Remove the last inserted element from the stack. Auxiliary stack operations: Top: returns the last inserted element without removing it. Size: returns the number of elements stored in stack. isemptystack: indicates whether any elements are stored in stack or not. 77
9 Exceptions Pop and top operations cannot be performed if the stack is empty. Attempting the execution of pop / top on an empty stack throws an exception. 78
10 Applications Direct applications: Balancing of symbols Infix-to-postfix expression Evaluation of postfix expression Implementing function calls (including recursion) Finding of spans Page visited history in a Web browser (back button) Undo sequence in a text editor Matching Tags in HTML and XML Indirect applications: Auxiliary data structure for other algorithms (example: Tree traversal algorithms) Component of other ADTs (example: simulating queues) 79
11 Formal description of a STACK Informal descriptions do not suffice. An abstract data type specification will show precisely how operations can be used It consists of four paragraphs: TYPES FUNCTIONS AXIOMS PRECONDITIONS 80
12 1* TYPES Indicates the types being specified Example Type: Stack Parameter: Element Use: Boolean Genericity Parameter is called a formal generic parameter of the abstract data type Stack, and Stack itself is said to be a generic ADT. 81
13 2* FUNCTIONS lists the operations applicable to instances of the ADT does not fully define these functions; it only introduces their signatures the list of their argument and result types. Functions: Create_stack : Stack isemptystack : Stack Boolean Push : Element Stack Stack Pop : Stack Stack Top : Stack Element Usage examples Create_stack() isemptystack(s) Push(El, S) Pop(S) Top(S) 82
14 Function categories Creators: Create a new instance of an ADT from instances of other types or from no argument at all. {OTHERS} ADT Queries: Functions that have a return value and do not change the instance. ADT {x OTHERS} OTHERS Commands: Functions without return value that change the instance. ADT {x OTHERS} ADT Constructors: Creators + Commands that add elements the ADT 83
15 3* AXIOMS Axioms that the ADT fulfills. Because any explicit definition would force us to select a representation, we must turn to implicit definitions. Refrain from giving the values of the functions of an ADT specification; instead state properties of these values all the properties that matter. Axioms: Let p be a Stack and e an Element: - isemptystack(create_stack()) = True - isemptystack(push(p,e)) = False - Pop(Push(p,e)) = p - Top(Push(p,e)) = e 84
16 Partial functions Some operations are not applicable to every possible element of their source sets. You cannot pop an element from an empty stack; An empty stack has no top. A function from a source set X to a target set Y is partialif it is not defined for all members of X. A function which is not partial is total. Example: division by 0. To indicate that a function may be partial, the notation uses the crossed arrow ; the normal arrow will be reserved for functions which are guaranteed to be total. The domainof a partial function in X Y is the subset of Xcontaining those elements for which the function yields a value. Example: for the inverse function, R\{0} is the domain. 85
17 4* PRECONDITIONS Preconditions that need to be fulfilled to apply a feature.\ Role of the PRECONDITIONS paragraph : Any ADT specification which includes partial functions must specify the domain of each of them. Preconditions: Let p be a Stack: Pop(p) is defined iffnot isemptystack(p) Top(p) is defined iffnot isemptystack(p) 86
18 Stack ADT Type: Stack Parameter: Element Use: Boolean Functions: Create_stack : Stack isemptystack : Stack Boolean Push : Element Stack Stack Pop : Stack Stack Top : Stack Element Constructors: Create_stack and Push top D C B A Push(D, Push(C, Push(B, Push(A, Create_stack() ) ) ) ) 87
19 Stack ADT Preconditions: Let p be a Stack: Pop(p) is defined iffnot isemptystack(p) Top(p) is defined iffnot isemptystack(p) Axioms: Let p be a Stack and e an Element: - isemptystack(create_stack()) = True - isemptystack(push(p,e)) = False - Pop(Push(p,e)) = p - Top(Push(p,e)) = e 88
20 Well-formed and correct terms Well-formed: all functions get a right number of arguments of right types Correct: preconditions of all functions are satisfied Examples: isemptystack(top(push(create_stack(), 3))) Top(Push(Create_stack(), 3)) 3 Top(Pop(Push(Create_stack(), 3))) isemptystack(pop(push(create_stack(), 7))) Top(Push(Push(Pop(Push(Create_stack(), 4)), 3), 2)) 2 ill-formed incorrect True 89
21 Sufficient completeness The specification contains axioms powerful enough to enable us to find the result of any query expression, in the form of a simple value. An ADT is sufficiently complete if and only if: 1. For every term t you can determine whether it is correct or not using the axioms of the ADT. 2. Every correct term where the outermost function is a query of the ADT can be reduced, using the axioms of the ADT, into a term not using any function of the ADT. In Rule 2, tem t is of the form (,, )where f is a query function, such as isemptystackand Top for stacks. Rule 1 tells us that t has a value, but this is not enough; in this case we also want to know what the value is, expressed only in terms of values of other types (in the STACK example, values of types BOOLEAN and ELEMENT). If the axioms are strong enough to answer this question in all possible cases, then the specification is sufficiently complete. 90
22 Implementation Many ways of implementing stack ADT: 1. Static (array) based implementation 2. Dynamic (Linked lists) based implementation
23 Header files 92
24 Header files A header file is a file with extension.h which contains C function declarations and macro definitions and to be shared between several source files. There are two types of header files: the files that the programmer writes and #include<stdio.h> the files that come with your compiler. #include stack.h Including a header file = copying the content of the header file 93
25 Header files A simple practice in C programs is that we keep all the constants, macros, system wide global variables, and function prototypes in header files and include that header file wherever it is required. 94
26 95
27 Rule #1 Each module with its.h and.c file should correspond to a clear piece of functionality. Conceptually, a module is a group of declarations and functions can be developed and maintained separately from other modules, and perhaps even reused in entirely different projects. 96
28 Rule #2 The header file contains only declarations, and is included by the.c file for the module. Put only structure type declarations, function prototypes, and global variable extern declarations, in the.h file; Put the function definitions and global variable definitions and initializations in the.c file. The.c file for a module must include the.h file; the compiler can detect discrepancies between the two, and thus help ensure consistency 97
29 Rule #3 Set up program-wide functions with an extern declaration in the header file, and a defining declaration in the.c file. 98
30 Rule #4 Keep a module s internal declarations out of the header file. 99
31 Rule #5 Every header file A.h should #include every other header file that A.h requires to compile correctly, but no more. 100
32 Rule #6 The A.c file should first #include its A.h file, and then any other headers required for its code 101
33 Rule #7 Never #include a.c file for any reason! 102
34 Static based implementation 103
35 Static based implementation top D tab tab[0] tab[1] tab[2] tab[3] tab[4] C B A 104
36 Static based implementation Example tab tab[0] tab[1] tab[2] tab[3] tab[4] Push(stack,A) Push(stack,B) Push(stack,C) Push(stack,D) Pop(stack) Push(stack,E) Push(stack,F) Push(stack,G) top A B C ED F 105
37 Static based implementation This implementation of stack ADT uses an array. In the array, we add elements from left to right and we use a variable to keep track of the index of the top element. S The array storing the stack elements may become full. A push operation will then throw a full stack exception. Push an element: increment top and store the element in the array Pop: decrement top top 106
38 Stack: implementation Type_Stack.h #define N 20 typedef element; typedef struct { element data[n]; /* stack content */ int top; } stack; 107
39 Stack: implementation Stack.h #include "Type_Stack.h" extern stack CreateStack(); extern int Push(stack *p, element e); extern int Pop(stack *p); extern int Top(stack p, element *e); extern int isemptystack(stack p); extern int isfullstack(stack p); 108
40 Stack: implementation Stack.c #include "Stack.h" stack CreateStack() { } p; p.top = -1; return p; 109
41 Stack: implementation Stack.c int Push(stack *p, element e) { if (isfullstack(*p)) return 0; p->data[++p->top] = e; return 1; } 110
42 Stack: implementation Stack.c int Pop(stack *p) { } if (isemptystack(*p)) return 0; p->top--; return 1; 111
43 Stack: implementation Stack.c int Top(stack p, element *e) { if (isemptystack(p)) return 0; *e = p.data[p.top]; return 1; } 112
44 Stack: implementation Stack.c int isemptystack(stack p) { return (p.top == -1); } int isfullstack(stack p) { return (p.top == N-1); } 113
45 Performance & Limitations Let n be the number of elements in the stack. Space complexity (for n push operations) Time complexity of Push() Ο 1 Time complexity of Pop() Ο 1 Time complexity of Top() Ο 1 Time complexity of IsEmptyStack() Ο 1 Time complexity of IsFullStack() Ο 1 The maximum size of the stack must be defined in prior and cannot be changed. Trying to push a new element into a full stack causes an implementationspecific exception. Ο 114
46 Exercise Give the content of the stack after each line of code. Give also the content of x and y, and the top of the stack. #define StackMax 5 float x; float y; stack s; int i, j; s=create_stack(); Push(&s,3.2); Push(&s,2.0); stack x y top Random
47 Exercise Top(s,&x); Pop(&s); Top(s,&y); Pop(&s); Push(&s,y-x); Push(&s,7.9); Push(&s,5.7); stack x y top
48 Exercise Top(s,&x); Pop(&s); Top(s,&y); Pop(&s); Push(&s,y+x); stack x y top
49 Exercise Top(s,&x); Pop(&s); Top(s,&y); Pop(&s); y*=x; stack x y top x
50 Exercise Push(&s,1.0); Push(&s,2.0); Push(&s,3.0); Push(&s,4.0); i=2; while(i>0) { Pop(&s); i--; } Top(s,&x); stack x y top
51 Exercise Push(&s,3.0); Push(&s,4.0); i=3; j=1; while(i>0) { i--; j--; if(j==0) 4.0 Top(s,&y); 3.0 Pop(&s); } 2.0 Top(s,&x); 1.0 stack x y top
52 Exercise Push(&s,3.0); Push(&s,4.0); while(top(s,&y)) { Pop(&s); if(top(s,&x)) { Pop(&s); Push(&s,x+y); } else break; } Push(&s,y); stack x y top
53 Dynamic based implementation 122
54 Cells t[0] t[1] t[2] t[3] t[4] t[5] t[6] t[7] t[8] struct cell { element data; struct cell *next; }
55 Dynamic based implementation Implementing stacks using linked lists Push operation is implemented by inserting element at the beginning of the list. Pop operation is implemented by deleting the node from the beginning. 124
56 Stack: implementation Type_Stack.h typedef element; typedef struct cell { element data; struct cell *next; } *stack; D temp CB Push A Push B Pop Push C Push D A NULL stack 125
57 Stack: implementation Stack.h #include "Type_Stack.h" extern stack CreateStack(); extern int Push(stack *p, element e); extern int Pop(stack *p); extern int Top(stack p, element *e); extern int isemptystack(stack p); extern int isfullstack(stack p); 126
58 Stack: implementation Stack.c #include "Stack.h" stack CreateStack() { return NULL; } 127
59 Stack: implementation Stack.c int Push(stack *p, element e) { stack temp; temp = (stack) malloc(sizeof(struct cell)); if(!temp) return 0; temp->data=e; } temp->next=*p; *p=temp; return 1; 128
60 Stack: implementation Stack.c int Pop(stack *p) { stack temp; if (isemptystack(*p)) return 0; temp =*p; *p = (*p)->next; } free(temp); return 1; 129
61 Stack: implementation Stack.c int Top(stack p, element *e) { if (isemptystack(p)) return 0; *e = p->data; return 1; } 130
62 Stack: implementation Stack.c int isemptystack(stack p) { return (p == NULL); } 131
63 Performance Let n be the number of elements in the stack. Space complexity (for n push operations) Ο Time complexity of Push() Ο 1 Time complexity of Pop() Ο 1 Time complexity of Top() Ο 1 Time complexity of IsEmptyStack() Ο 1 132
64 Comparing static and dynamic implementations Static implementation Operations take constant time. Any sequence of n operations (starting from empty stack) takes time proportional to n. Dynamic implementation Grows and shrinks gracefully. Every operation takes constant time Ο 1. Every operation uses extra space and time to deal with references. 133
65 Exercise Write a program in C showing how stacks can be used for checking balancing of symbols. Examples: Example Valid? Description (A+B)+(C-D) Yes The expression is having balanced symbols ((A+B)+(C-D) No One closing parenthesis is missing ((A+B)+[C-D]) Yes Opening and immediate closing braces correspond ((A+B)+[C-D]} No The last closing brace does not correspond with the first opening parenthesis 134
66 Exercise top ()(()[()]) 135
67 Exercise Algorithm: 1. Create a stack 2. While (end of input is not reached) { 1. If the character read is not a symbol to be balanced, ignore it. 2. If the character is an opening symbol like (, {, [, push it onto the stack. 3. If it is a closing symbol like ), }, ], then if the stack is empty, report an error. Otherwise, get the top element of the stack. 4. If the symbol popped is not the corresponding opening symbol, report an error 3. At the end of input, if the stack is not empty, report an error. 136
68 Solution 137
69 138
70 Solution 139
Overview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example
Overview of today s lecture Introduction to C programming, lecture 2 -Dynamic data structures in C Quick recap of previous C lectures Abstract data type - Stack example Make Refresher: pointers Pointers
More informationStack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5
What is Stack? Stack 1. Stack is LIFO Structure [ Last in First Out ] 2. Stack is Ordered List of Elements of Same Type. 3. Stack is Linear List 4. In Stack all Operations such as Insertion and Deletion
More informationSoftware Architecture. Abstract Data Types
Software Architecture Abstract Data Types Mathematical description An ADT is a mathematical specification Describes the properties and the behavior of instances of this type Doesn t describe implementation
More informationThe Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.
The Stack ADT Stacks Set of objects in which the location an item is inserted and deleted is prespecified Stacks! Insert in order! Delete most recent item inserted! LIFO - last in, first out Stacks 2 The
More informationABSTRACT DATA TYPES (ADTS) COMP1927 Computing 2 16x1 Sedgewick Chapter 4
ABSTRACT DATA TYPES (ADTS) COMP1927 Computing 2 16x1 Sedgewick Chapter 4 ABSTRACTION To understand a system, it should be enough to understand what its components do without knowing how Watching a television
More informationCS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type
More informationStacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)
Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria
More informationStacks. Manolis Koubarakis. Data Structures and Programming Techniques
Stacks Manolis Koubarakis 1 Stacks and Queues Linear data structures are collections of components arranged in a straight line. If we restrict the growth of a linear data structure so that new components
More informationStacks and Queues. CSE Data Structures April 12, 2002
Stacks and Queues CSE 373 - Data Structures April 12, 2002 Readings and References Reading Section 3.3 and 3.4, Data Structures and Algorithm Analysis in C, Weiss Other References 12-Apr-02 CSE 373 - Data
More informationChapter 19: Program Design. Chapter 19. Program Design. Copyright 2008 W. W. Norton & Company. All rights reserved.
Chapter 19 Program Design 1 Introduction Most full-featured programs are at least 100,000 lines long. Although C wasn t designed for writing large programs, many large programs have been written in C.
More informationData Structures & Algorithm Analysis. Lecturer: Souad Alonazi
Data Structures & Algorithm Analysis Lec(3) Stacks Lecturer: Souad Alonazi What is a stack? Stores a set of elements in a particular order Stack principle: LAST IN FIRST OUT = LIFO It means: the last element
More informationLinked List. April 2, 2007 Programming and Data Structure 1
Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element
More informationDATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which
More information08 STACKS DATA STRUCTURES AND ALGORITHMS IMPLEMENTATION & APPLICATIONS IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD
DATA STRUCTURES AND ALGORITHMS 08 STACKS IMPLEMENTATION & APPLICATIONS IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD WWW.IMRANIHSAN.COM LECTURES ADAPTED FROM: DANIEL KANE, NEIL RHODES DEPARTMENT
More informationOutline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks
Stack Chapter 4 Outline Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications Recursive Programming Evaluation of Expressions ADT for stacks Introduction
More informationSolution for Data Structure
Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT
More informationCpt S 122 Data Structures. Course Review Midterm Exam # 1
Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:
More informationADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )
ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a
More informationData Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1
Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Stack Operations on a stack Representing stacks Converting an expression
More informationFile Input and Output
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 153] File Input and Output File I/O is much simpler than in Java. æ Include stdio.h to use built-in file functions and types æ Declare
More informationLIFO : Last In First Out
Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.
More informationList, Stack and Queue Implementation
Roy Chan CSC2100B Data Structures Tutorial 2 (Version 2) January 21, 2009 1 / 39 1 CSC2100B Online Judge Score 2 Structure 3 Linked List Overview Implementation 4 Stack Overview Implementation 5 Queue
More informationLargest Online Community of VU Students
WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more
More informationStacks, Queues (cont d)
Stacks, Queues (cont d) CSE 2011 Winter 2007 February 1, 2007 1 The Adapter Pattern Using methods of one class to implement methods of another class Example: using List to implement Stack and Queue 2 1
More informationLists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50
Lists, Stacks, and Queues (Lists, Stacks, and Queues ) Data Structures and Programming Spring 2016 1 / 50 Abstract Data Types (ADT) Data type a set of objects + a set of operations Example: integer set
More informationLecture 10 Notes Linked Lists
Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to
More informationStacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack.
Stacks CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack Hours: 12 Marks: 18 3.1 Introduction to Stacks 1. Stack as Abstract
More informationSoftware Architecture. Abstract Data Types
Software Architecture Abstract Data Types Mathematical description An ADT is a mathematical specification Describes the properties and the behavior of instances of this type Doesn t describe implementation
More informationAbstract Data Types and Stacks
Abstract Data Types and Stacks CSE 2320 Algorithms and Data Structures Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington Last updated: 2/14/2017 1 Generalized Queues A generalized
More informationMID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.
MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions
More informationAssociate Professor Dr. Raed Ibraheem Hamed
Associate Professor Dr. Raed Ibraheem Hamed University of Human Development, College of Science and Technology Computer Science Department 2015 2016 1 What this Lecture is about: Stack Structure Stack
More informationADT Stack. Inserting and deleting elements occurs at the top of Stack S. top. bottom. Stack S
Stacks Stacks & Queues A linear sequence, or list, is an ordered collection of elements: S = (s 1, s 2,..., s n ) Stacks and queues are finite linear sequences. A Stack is a LIFO (Last In First Out) list.
More informationStacks Fall 2018 Margaret Reid-Miller
Stacks 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Today: Quiz 5 solutions Recursive add from last week (see SinglyLinkedListR.java) Stacks ADT (Queues on Thursday) ArrayStack
More informationTwo approaches. array lists linked lists. There are two approaches that you can take:
Lists 1 2 Lists 3 A list is like an array, except that the length changes. Items are added to a list over time, and you don't know in advance how many there will be. This chapter implements lists in two
More informationSTACKS AND QUEUES. Problem Solving with Computers-II
STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()
More informationStacks Stack Examples:
Stacks 1 Stacks A Stack is a sequential organization of items in which the last element inserted is the first element removed. They are often referred to as LIFO, which stands for last in first out. Examples:
More informationChapter 9 STACK, QUEUE
Chapter 9 STACK, QUEUE 1 LIFO: Last In, First Out. Stacks Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP. Stack
More informationStacks and Queues. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms
Stacks and Queues Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Two New ADTs Define two new abstract data types Both are restricted lists Can be implemented using arrays
More informationStack & Queue on Self-Referencing Structures
C Programming 1 Stack & Queue on Self-Referencing Structures C Programming 2 Representation of Stack struct stack { int data ; struct stack *next ; ; typedef struct stacknode node, *stack ; C Programming
More informationLecture 10 Notes Linked Lists
Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Summer 1 2015) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to
More informationSTACKS 3.1 INTRODUCTION 3.2 DEFINITION
STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called
More informationData Structures Week #3. Stacks
Data Structures Week #3 Stacks Outline Stacks Operations on Stacks Array Implementation of Stacks Linked List Implementation of Stacks Stack Applications October 5, 2015 Borahan Tümer, Ph.D. 2 Stacks (Yığınlar)
More informationStacks. Revised based on textbook author s notes.
Stacks Revised based on textbook author s notes. Stacks A restricted access container that stores a linear collection. Very common for solving problems in computer science. Provides a last-in first-out
More informationMIDTERM EXAMINATION Spring 2010 CS301- Data Structures
MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur Conceptual Idea
More informationLecture 3: Stacks & Queues
Lecture 3: Stacks & Queues Prakash Gautam https://prakashgautam.com.np/dipit02/ info@prakashgautam.com.np 22 March, 2018 Objectives Definition: Stacks & Queues Operations of Stack & Queues Implementation
More informationContainers: Stack. Jordi Cortadella and Jordi Petit Department of Computer Science
Containers: Stack Jordi Cortadella and Jordi Petit Department of Computer Science The Stack ADT A stack is a list of objects in which insertions and deletions can only be performed at the top of the list.
More informationEC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3
UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between
More informationOutline and Reading. The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.
Stacks Outline and Reading The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.5) Stacks 2 Abstract Data Types (ADTs) An abstract data
More information17CS33:Data Structures Using C QUESTION BANK
17CS33:Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C Learn : Usage of structures, unions - a conventional tool for handling a group of logically
More informationStacks CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008
Chapter 7 s CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008 The Abstract Data Type: Specifications of an abstract data type for a particular problem Can emerge during the design of the
More informationStack & Queue on Self-Referencing Structures
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 Stack & Queue on Self-Referencing Structures PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Representation of Stack struct stack { int data ; struct
More informationContainers: Stack. The Stack ADT. The Stack ADT. The Stack ADT
Containers: Stack The Stack ADT A stack is a list of objects in which insertions and deletions can only be performed at the top of the list. Also known as LIFO Last In, First Out) push insert an element
More informationMULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR
STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM
More informationOutline. Stacks. 1 Chapter 5: Stacks and Queues. favicon. CSI33 Data Structures
Outline Chapter 5: and Queues 1 Chapter 5: and Queues Chapter 5: and Queues The Stack ADT A Container Class for Last-In-First-Out Access A stack is a last in, first out (LIFO) structure, i.e. a list-like
More informationIntroduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms
Introduction Problem Solving on Computer Data Structures (collection of data and relationships) Algorithms 1 Objective of Data Structures Two Goals: 1) Identify and develop useful high-level data types
More informationCOMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004)
COMP250: Stacks Jérôme Waldispühl School of Computer Science McGill University Based on slides from (Goodrich & Tamassia, 2004) 2004 Goodrich, Tamassia The Stack ADT A Stack ADT is a list that allows only
More informationStack and Its Implementation
Stack and Its Implementation Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131 1 Definition of Stack Usage of Stack Outline
More informationCH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES
CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER
More informationIV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard
IV. Stacks 1 A. Introduction 1. Consider the problems on pp. 170-1 (1) Model the discard pile in a card game (2) Model a railroad switching yard (3) Parentheses checker () Calculate and display base-two
More informationCSE 214 Computer Science II Stack
CSE 214 Computer Science II Stack Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Random and Sequential Access Random
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours
TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART
More informationC Syntax Out: 15 September, 1995
Burt Rosenberg Math 220/317: Programming II/Data Structures 1 C Syntax Out: 15 September, 1995 Constants. Integer such as 1, 0, 14, 0x0A. Characters such as A, B, \0. Strings such as "Hello World!\n",
More informationData Abstraction and Specification of ADTs
CITS2200 Data Structures and Algorithms Topic 4 Data Abstraction and Specification of ADTs Example The Reversal Problem and a non-adt solution Data abstraction Specifying ADTs Interfaces javadoc documentation
More informationLecture Notes on Memory Layout
Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,
More informationStacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved
Stacks Chapter 5 Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced Delimiters in an Infix Algebraic Expression A Problem Solved:
More informationMODULE 5: Pointers, Preprocessor Directives and Data Structures
MODULE 5: Pointers, Preprocessor Directives and Data Structures 1. What is pointer? Explain with an example program. Solution: Pointer is a variable which contains the address of another variable. Two
More informationFun facts about recursion
Outline examples of recursion principles of recursion review: recursive linked list methods binary search more examples of recursion problem solving using recursion 1 Fun facts about recursion every loop
More informationCSE 230 Intermediate Programming in C and C++
CSE 230 Intermediate Programming in C and C++ Structures and List Processing Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Self-referential Structure
More informationObject-Oriented Software Construction
1 Object-Oriented Software Construction Bertrand Meyer Reading assignment 2 OOSC2 Chapter 10: Genericity 3 Lecture 4: Abstract Data Types Abstract Data Types (ADT 4 Why use the objects? The need for data
More informationStacks Calculator Application. Alexandra Stefan
Stacks Calculator Application Alexandra Stefan Last modified 2/6/2018 1 Infix and Postfix Notation The standard notation we use for writing mathematical expressions is called infix notation. The operators
More informationcsci 210: Data Structures Stacks and Queues
csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks
More informationCMSC 4023 Chapter 11
11. Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized Abstract Data Types Encapsulation Constructs Naming Encapsulations
More informationTechnical Questions. Q 1) What are the key features in C programming language?
Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationLecture 4 Stack and Queue
Lecture 4 Stack and Queue Bo Tang @ SUSTech, Spring 2018 Our Roadmap Stack Queue Stack vs. Queue 2 Stack A stack is a sequence in which: Items can be added and removed only at one end (the top) You can
More informationLecture Notes on Queues
Lecture Notes on Queues 15-122: Principles of Imperative Computation Frank Pfenning and Jamie Morgenstern Lecture 9 February 14, 2012 1 Introduction In this lecture we introduce queues as a data structure
More informationCMPT 225. Lecture 9 Stack
CMPT 225 Lecture 9 Stack 1 Last Lecture We did an activity about Stack 2 Learning Outcomes 3 At the end of this lecture (and the activity), a student will be able to: Describe Stack Define public interface
More informationAbstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1
Abstract Data Types Stack January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract data types and data structures An Abstract Data Type (ADT) is: A collection of data Describes what data are stored but
More informationQueues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1
Queues October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queue ADT Queue ADT should support at least the first two operations: enqueue insert an item to the back of the queue dequeue remove an item from
More informationArrays and Linked Lists
Arrays and Linked Lists Abstract Data Types Stacks Queues Priority Queues and Deques John Edgar 2 And Stacks Reverse Polish Notation (RPN) Also known as postfix notation A mathematical notation Where every
More informationData Structures and Algorithms. Chapter 5. Dynamic Data Structures and Abstract Data Types
1 Data Structures and Algorithms Chapter 5 and Abstract Data Types Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press
More informationPrepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon
Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements
More information15. Stacks and Queues
COMP1917 15s2 15. Stacks and Queues 1 COMP1917: Computing 1 15. Stacks and Queues Reading: Moffat, Section 10.1-10.2 Overview Stacks Queues Adding to the Tail of a List Efficiency Issues Queue Structure
More informationDEEPIKA KAMBOJ UNIT 2. What is Stack?
What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you
More informationStacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved
Stacks Chapter 5 Copyright 2012 by Pearson Education, Inc. All rights reserved Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced
More informationA complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
More informationVTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS THE STACK
Contents: Definition and Examples Representing stacks in C Example: infix, prefix, and postfix Exercises THE STACK Definition and Examples A stack is an ordered collection of items into which new items
More information[CS302-Data Structures] Homework 2: Stacks
[CS302-Data Structures] Homework 2: Stacks Instructor: Kostas Alexis Teaching Assistants: Shehryar Khattak, Mustafa Solmaz, Bishal Sainju Fall 2018 Semester Section 1. Stack ADT Overview wrt Provided Code
More informationPrepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1
Basics : Abstract Data Type(ADT) introduction to data structures representation - implementation Stack and list: representing stack implementation application balancing symbols conversion of infix to postfix
More informationn Data structures that reflect a temporal relationship q order of removal based on order of insertion n We will consider:
Linear, time-ordered structures CS00: Stacks n Prichard Ch 7 n Data structures that reflect a temporal relationship order of removal based on order of insertion n We will consider: first come,first serve
More informationPreface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS
Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...
More informationProblem with Scanning an Infix Expression
Operator Notation Consider the infix expression (X Y) + (W U), with parentheses added to make the evaluation order perfectly obvious. This is an arithmetic expression written in standard form, called infix
More informationIT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science
IT 4043 Data Structures and Algorithms Budditha Hettige Department of Computer Science 1 Syllabus Introduction to DSA Abstract Data Types List Operation Using Arrays Stacks Queues Recursion Link List Sorting
More informationCpt S 122 Data Structures. Data Structures
Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation
More informationToday s lecture. CS 314 fall 01 C++ 1, page 1
Today s lecture Midterm Thursday, October 25, 6:10-7:30pm general information, conflicts Object oriented programming Abstract data types (ADT) Object oriented design C++ classes CS 314 fall 01 C++ 1, page
More information1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \
BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,
More informationName :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70
Name :. Roll No. :..... Invigilator s Signature :.. 2011 INTRODUCTION TO PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give
More information