Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Stacks Example: Stack of plates in cafeteria.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 06 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 17 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
Objectives of these slides:
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.
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Chapter 4 Stacks Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving. Its called.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
CHAPTER 61 STACK, QUEUES, RECURSION. Introduction when one wants to restrict insertion and deletion so that they can take place only at the beginning.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Stack Any Other Data Structure Array Linked List
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues (part 2)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 2)
CHP-3 STACKS.
Lecture - 6(Stacks) On Data structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Lecture Outline What is a Stack? Array implementation of stacks Operations.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Review Use of Stack Introduction Stack in our life Stack Operations
STACKS & QUEUES for CLASS XII ( C++).
Data Structures Using C++ 2E
Review Array Array Elements Accessing array elements
Data Structures Using C, 2e
Queues.
Data Structure By Amee Trivedi.
Introduction Of Stack.
Infix to postfix conversion
MEMORY REPRESENTATION OF STACKS
Lecture No.06 Data Structures Dr. Sohail Aslam
Objectives In this lesson, you will learn to: Define stacks
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Queues Queues Queues.
Data Structures Interview / VIVA Questions and Answers
Stacks.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
STACKS.
Stacks Stack: restricted variant of list
Data Structures – Week #3
Stack application: postponing data usage
Algorithms and Data Structures
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
PART II STACK APPLICATIONS
Stack Data Structure, Reverse Polish Notation, Homework 7
CMSC 341 Lecture 5 Stacks, Queues
Stacks Chapter 5 Adapted from Pearson Education, Inc.
STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.
Arrays and Linked Lists
Stacks, Queues, and Deques
STACK, QUEUES, RECURSION
UNIT-I Topics to be covere d 1.Introduction to data structures.
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Data structures.
Stacks and Queues 1.
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Visit for more Learning Resources
Queue Applications Lecture 31 Tue, Apr 11, 2006.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
LINEAR DATA STRUCTURES
DATA STRUCTURES IN PYTHON
Presentation transcript:

Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai Stack Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai 8/27/2019

Topics to Cover . . . Introduction to some Data Structures Stack – An Introduction Stack – Operations Implementation of Stack Stack using Arrays Applications of Stack Conversion of Infix to Postfix polish notation Evaluation of Postfix expression Questions (Homework Assignment) 8/27/2019

Introduction of Some Data Structures Arrays Linked List Queue Stack 8/27/2019

Arrays 8/27/2019

LINKED LISTS – Connects Nodes 8/27/2019

Queue - FIFO A queue is like a line of people waiting for a bank teller. The queue has a front and a rear. $ $ Front Rear When you think of a computer science queue, you can imagine a line of people waiting for a teller in a bank. The line has a front (the next person to be served) and a rear (the last person to arrive. 8/27/2019

STACKS - LIFO In this Example, we had entered 1, 3 & 9 in the order but we have to retrieve 9 first . 8/27/2019

The Stack Operations Insertion - New data must enter the Stack at the TOP. It is usually called an Push operation. Don’t ask me why the C++ STL used the name push. It only confuses matters with a stack. In any case, when a new item enters a queue, it does so at the rear. 8/27/2019

The Stack Operations Deletion - When an item is taken from the Stack, it always comes from the TOP. It is usually called a Pop operation. When an item is removed from a queue, the removal occurs at the front. 8/27/2019

Implementation of Stack Static Stack – Using Arrays Dynamic Stack – Using Linked Lists 8/27/2019

Implementation using Array It is also Called as Static Stack 8/27/2019

Operations on Stack using Array PUSH Operation ALGORITHM : 1. If TOP = N, then : Print OVERFLOW and Return. 2. Set TOP := TOP + 1. 3. Set STACK[TOP] := ITEM. 4. Return. 8/27/2019

Operations on Stack using Array POP Operation ALGORITHM : 1. If TOP = 0, then : Print UNDERFLOW and Return. 2. Set ITEM:= STACK[TOP]. 3. Set TOP := TOP - 1. 4. Return. 8/27/2019

Review Questions 1. What do you mean by PUSH in terms of Stack? 2. What do you mean by UNDERFLOW & OVERFLOW. 3. What are the different ways to implement Stack? 4. What do you mean by dynamic Stack? 8/27/2019

Applications of Stack Infix to Postfix Conversion Evaluation of Postfix Expression 8/27/2019

Infix to Postfix Conversion Polish Notation The order in which any Operation is performed is determined by the position of Operator & Operands in the expression. Types of Polish notations : Infix Prefix Postfix A + B +AB AB+ 8/27/2019

Infix to Postfix Conversion Precedence of Operators The order in which any Operation is performed in the expression. Exponentiation (  ) Multiplication ( * ) & Division ( / ) Addition ( + ) & Subtraction( - ) 8/27/2019

Infix to Postfix Conversion Need of converting Infix to Postfix While using INFIX Compiler needs to remember the precedence of operators to solve the equation, which is tedious task but if we convert it into post fix notation then it arranges Operators according to their precedence. So, Compiler doesn’t needs to remember that so it saves time & Complexity. 8/27/2019

Infix to Postfix Conversion ALGORITHM 1. Push “(“ onto Stack and Add “)” to the end of Q. 2. Scan Q from left to right and repeat steps 3 to 6 for each element of Q until Stack is empty: 3. If an operand is encountered, add it to P. 4. If a Left parenthesis is encountered, push it on Stack. 5. If an Operator ¤ encountered, then : a) Repeatedly pop from Stack and add to P each operator which has the same precedence as or higher precedence than ¤. b) Add ¤ to the Stack. [ End of If Structure] 8/27/2019

Infix to Postfix Conversion ALGORITHM 6. If a Right parenthesis is encountered, then : a) Repeatedly pop from Stack and add to P each operator until a Left parenthesis is encountered. b) Remove the left Parenthesis. [ End of If Structure] [End of step 2 Loop] 7. Exit. 8/27/2019

Q : A + ( B * C – ( D / E  F ) * G ) * H Example : Q : A + ( B * C – ( D / E  F ) * G ) * H 8/27/2019

Q : A + ( B * C – ( D / E  F ) * G ) * H 8/27/2019

Q : A + ( B * C – ( D / E  F ) * G ) * H 8/27/2019

Evaluation of Postfix Expression 1. Add a right parenthesis “)“ at the end of P. 2. Scan p from left to right and repeat step 3 & 4 for each until the sentinel “)” is encountered. 3. If an operand is encountered, put it on Stack. 4. If an operator ¤ is encountered, then : a) Pop the two top elements of Stack, Say A(Top most) and B(Second Top). b) Evaluate A ¤ B. c) Push the result in Stack. [End of If structure] [End of step 2 Loop] 5. Set Value equal to top element of Stack. 6. Exit. 8/27/2019

EXAMPLE P : 5 6 2 + * 12 4 / - As You can see now P is empty i.e. there is no more element in P. So, Value at Stack[TOP] is your answer. In this case it is 37 8/27/2019

Homework Assignment 1. Convert following Infix expression to Postfix : X – y / (z + u) * V 100 + 20 – 50 / 15 * 4 + (8 + 7) 2. Evaluate Following Postfix Expressions: T, F, NOT, AND, F, T, OR, AND 10 20 + 25 15 - * 30 / 8/27/2019

THANX A LOT QUERIES ??? 8/27/2019

Static vs. Dynamic Structures Static Data Structures Fast access to elements Expensive to insert/remove element Have fixed maximum size Memory is reserved at the time of compilation. e.g. Arrays 8/27/2019

Static vs. Dynamic Structures Dynamic Data Structures Fast insertion/deletion of element Slower access to the element Have flexible size Memory allocation for the data structure takes place at the run time, only required amount of memory is allocated. e.g. Linked lists, Stacks, Queues, Trees etc. 8/27/2019

Static vs. Dynamic Structures A static data structure has a fixed size e.g. Arrays are static; once you define the number of elements it can hold, the number doesn’t change A dynamic data structure grows and shrinks at execution time as required by its contents A dynamic data structure is implemented using links 8/27/2019

Drawbacks of Static Data Structures Memory – We had to define memory in advance which will either waste Memory or create the space problem Time – For Insertion & Deletion 8/27/2019

Array Implementation A Stack can be implemented with an array, as shown here. Just like our stack implementation in the previous chapter, one way to implement a queue is to store the elements in an array. 8/27/2019