SlideShare a Scribd company logo
1 of 13
Introduction To Stack 
By: 
Dr. Ghulam Rasool
Stack 
โ€ข A variable sized data structure in which insertion or deletion 
is made just from one end 
or 
โ€ข A LIFO data structure is called Stack 
Operations on Stack 
1) Push ( to insert an element into stack) 
2) Pop( to take an element out of stack) 
The last element inserted is deleted or taken out first and 
first element at last 
The stack can be implemented using Array as well as Link 
List
Stack using Arrays 
โ€ข The no of elements that can be inserted in a the stack is 
the dimension of array. The current position of stack(i.e 
its size is known by a pointer called its top. 
Algorithm to insert data in stack Push(S,Top, X, N) 
1 If Top >= N then 
wrtie (โ€˜Stack fullโ€™) and exit 
2 Top=Top+1 
3 S[Top]= X 
4 Exit
Stack Operations 
Algorithm to delete an element from Stack Pop(S, Top) 
1 If Top= 0 then 
write(โ€˜ stack is emptyโ€™) and exit 
2 Pop = S[Top] 
3 Top= Top-1 
4 Exit 
Applications of Stack 
i) Recursion 
ii) Evaluation of Arithmetic expressions 
a) Infix notation 
b) prefix notations 
c) postfix notations
Recursion 
โ€ข The calling of a subprogram to itself is called recursions 
Examples: Factorial of a number 
Fact(N) 
1) If N= 0 then 
Fact =1 
2) Fact= N* Fact(N-1) 
Polish Suffix notations 
โ€ข It is named after Polish mathematician Jan Lukasiewiez. 
The operator symbol is placed before its two operands in 
this notations 
โ€ข Examples: AB+, CD-, EF*
PSN notations 
โ€ข The expressions in which operands are preceded by the 
operators are called PSN notations or postfix notations. 
โ€ข Example: Following are PSN notations 
AB+ 
DE* 
ABC*+ 
โ€ข Convert A+B*C into PSN 
Symbol scanned operator Stack PSN 
A A 
+ + A 
B + AB 
* +* AB 
C +* ABC 
$ ABC *+
RPN(Q, P) 
โ€ข Suppose Q is expression in infix form. This algorithm 
covert this expression into equivalent postfix expression P 
1) Scan Q from left to right and repeat Steps 2 to 5 for each 
element of Q until the end of Expression 
2) If an operand is encountered, add it to P 
3) If a left parenthesis is encountered, push it onto stack 
4) If an operator is 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 stack 
5) 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 left parenthesis 
6) Exit
Quiz 1 
โ€ข Q.1 What is difference b/w Stack and Array. 
Can a stack be an array and an array can be a 
stack? 
โ€ข Q.2 Convert following expressions into PSN 
((A- (B+C)) *D)^(E+F)
Assignment I 
Q.2 Write a program that should take infix expression and convert it 
into PSN. The program should also evaluate PSN expression.
Algorithm for evaluation of PSN 
1 Scan the Postfix string from left to right. 
2 Initialise an empty stack. 
3 Repeat step 4 until the end of string 
4 If the scanned character is an operand, Push 
it to the stack. 
a) If the scanned character is an Operator, pop top 
two elements and apply operator. 
b) Push result back on top of stack 
5 Pop last value from stack 
5 Exit.
Example 
โ€ข infix expression: 1+ 2 *3 
โ€ข Postfix : 1 2 3 + * 
Symbol Stack 
1 1 
2 1, 2 
3 1, 2, 3 
+ 1, 5 
* 5
Towers of Hanoi 
โ€ข Suppose three Pegs labled A, B and C and Suppose on Peg A 
there are placed a finite number n of disks with decreasing size. 
โ€ข The objective of game is to move the disks from Peg A to PegC 
using Peg B as an intermediate. 
โ€ข The rules of game are as: 
i) Only one disk may be moved at a time, specifically only the 
top disk on any Peg may be moved to any other Peg. 
ii) A larger disk can not be placed on a smaller disk 
โ€ข Example: For n=3 
โ€ข Move top disk from A to C Move top disk from A to C 
โ€ข Move top disk from A to B Move top disk from B to A 
โ€ข Move top disk from C to B Move top disk from B to C 
โ€ข Move top disk from A to C
Recursive Solution 
1 Move top n-1 disks from A to B 
2 Move the top disk from A to C 
3 Move the top n-1 disks from B to C 
General notation: 
Tower(N, Beg, Sec, End) 
When N=1 
Tower(1, Beg, Sec, End) 
When N>1 
Tower( N-1 Beg, End, Sec) 
Tower(1, Beg, Sec, End) Beg โ€ฆ> End 
Tower( N-1, Sec, Beg, End)

More Related Content

What's hot

Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackSoumen Santra
ย 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
ย 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data StructureBhavesh Sanghvi
ย 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and ApplicationsSagacious IT Solution
ย 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversionThen Murugeshwari
ย 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
ย 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
ย 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
ย 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
ย 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
ย 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTUREMandeep Singh
ย 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9sumitbardhan
ย 

What's hot (20)

Stack
StackStack
Stack
ย 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
ย 
Stacks
StacksStacks
Stacks
ย 
Queues
QueuesQueues
Queues
ย 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
ย 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
ย 
stack presentation
stack presentationstack presentation
stack presentation
ย 
Stack
StackStack
Stack
ย 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
ย 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
ย 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
ย 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
ย 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
ย 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
ย 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
ย 
Stack data structure
Stack data structureStack data structure
Stack data structure
ย 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
ย 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
ย 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
ย 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9
ย 

Viewers also liked

Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queueSrajan Shukla
ย 
Improving Pronunciation
Improving PronunciationImproving Pronunciation
Improving PronunciationEducation Front
ย 
Data Representation
Data RepresentationData Representation
Data RepresentationEducation Front
ย 
Introduction To Data Structures.
Introduction To Data Structures.Introduction To Data Structures.
Introduction To Data Structures.Education Front
ย 
Computer Evolution
Computer EvolutionComputer Evolution
Computer EvolutionEducation Front
ย 
Introduction to Algorithm
Introduction to AlgorithmIntroduction to Algorithm
Introduction to AlgorithmEducation Front
ย 
Programming Language
Programming LanguageProgramming Language
Programming LanguageEducation Front
ย 
Processor Basics
Processor BasicsProcessor Basics
Processor BasicsEducation Front
ย 
Register & Memory
Register & MemoryRegister & Memory
Register & MemoryEducation Front
ย 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1Motaz Saad
ย 
Linked list
Linked listLinked list
Linked listakshat360
ย 
Data Representation
Data RepresentationData Representation
Data RepresentationEducation Front
ย 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
ย 

Viewers also liked (13)

Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
ย 
Improving Pronunciation
Improving PronunciationImproving Pronunciation
Improving Pronunciation
ย 
Data Representation
Data RepresentationData Representation
Data Representation
ย 
Introduction To Data Structures.
Introduction To Data Structures.Introduction To Data Structures.
Introduction To Data Structures.
ย 
Computer Evolution
Computer EvolutionComputer Evolution
Computer Evolution
ย 
Introduction to Algorithm
Introduction to AlgorithmIntroduction to Algorithm
Introduction to Algorithm
ย 
Programming Language
Programming LanguageProgramming Language
Programming Language
ย 
Processor Basics
Processor BasicsProcessor Basics
Processor Basics
ย 
Register & Memory
Register & MemoryRegister & Memory
Register & Memory
ย 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
ย 
Linked list
Linked listLinked list
Linked list
ย 
Data Representation
Data RepresentationData Representation
Data Representation
ย 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
ย 

Similar to Introduction To Stack

Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxchandankumar364348
ย 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7Kumar
ย 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxprakashvs7
ย 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
ย 
Stack application
Stack applicationStack application
Stack applicationStudent
ย 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxkumarkaushal17
ย 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESSowmya Jyothi
ย 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxYogesh Pawar
ย 
DS UNIT1_STACKS.pptx
DS UNIT1_STACKS.pptxDS UNIT1_STACKS.pptx
DS UNIT1_STACKS.pptxVeerannaKotagi1
ย 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxhaaamin01
ย 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
ย 
Concept of stack ,stack of aaray stack by linked list , application of stac...
Concept of stack ,stack of aaray   stack by linked list , application of stac...Concept of stack ,stack of aaray   stack by linked list , application of stac...
Concept of stack ,stack of aaray stack by linked list , application of stac...muskankumari7360
ย 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureAfaq Mansoor Khan
ย 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms StacksManishPrajapati78
ย 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++Vineeta Garg
ย 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure DivyeshKumar Jagatiya
ย 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
ย 

Similar to Introduction To Stack (20)

Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
ย 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
ย 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
ย 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
ย 
Stack application
Stack applicationStack application
Stack application
ย 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
ย 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
ย 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
ย 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
ย 
DS UNIT1_STACKS.pptx
DS UNIT1_STACKS.pptxDS UNIT1_STACKS.pptx
DS UNIT1_STACKS.pptx
ย 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
ย 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
ย 
Concept of stack ,stack of aaray stack by linked list , application of stac...
Concept of stack ,stack of aaray   stack by linked list , application of stac...Concept of stack ,stack of aaray   stack by linked list , application of stac...
Concept of stack ,stack of aaray stack by linked list , application of stac...
ย 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
ย 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ย 
Sorting
SortingSorting
Sorting
ย 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
ย 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
ย 
Stack
StackStack
Stack
ย 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
ย 

More from Education Front

Generic Software Process Models
Generic Software Process ModelsGeneric Software Process Models
Generic Software Process ModelsEducation Front
ย 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional ArraysEducation Front
ย 
Problem Sloving
Problem SlovingProblem Sloving
Problem SlovingEducation Front
ย 
Problem Solving - 1
Problem Solving - 1Problem Solving - 1
Problem Solving - 1Education Front
ย 
Revised Process of Communication
Revised Process of CommunicationRevised Process of Communication
Revised Process of CommunicationEducation Front
ย 
Importance of Language in Communication
Importance of Language in CommunicationImportance of Language in Communication
Importance of Language in CommunicationEducation Front
ย 
Lecture1 (SE Introduction)
Lecture1 (SE Introduction)Lecture1 (SE Introduction)
Lecture1 (SE Introduction)Education Front
ย 
Lecture 2 (Software Processes)
Lecture 2 (Software Processes)Lecture 2 (Software Processes)
Lecture 2 (Software Processes)Education Front
ย 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureEducation Front
ย 
Facing Todayโ€™s Communication Challenges
Facing Todayโ€™s Communication ChallengesFacing Todayโ€™s Communication Challenges
Facing Todayโ€™s Communication ChallengesEducation Front
ย 
Introduction To EMU
Introduction To EMUIntroduction To EMU
Introduction To EMUEducation Front
ย 
Lecture 2: Facing Todayโ€™s Communication Challenges.
Lecture 2: Facing Todayโ€™s Communication Challenges.Lecture 2: Facing Todayโ€™s Communication Challenges.
Lecture 2: Facing Todayโ€™s Communication Challenges.Education Front
ย 
Effective communication skills
Effective communication skillsEffective communication skills
Effective communication skillsEducation Front
ย 
Introduction to Presentation Skills
Introduction to Presentation SkillsIntroduction to Presentation Skills
Introduction to Presentation SkillsEducation Front
ย 
Multiple Drug Resistance and Antibiotic Misuse in Urdu.
Multiple Drug Resistance and Antibiotic Misuse in Urdu.Multiple Drug Resistance and Antibiotic Misuse in Urdu.
Multiple Drug Resistance and Antibiotic Misuse in Urdu.Education Front
ย 
Multiple Drug Resistance and Antibiotic Misuse In English.
Multiple Drug Resistance and Antibiotic Misuse In English.Multiple Drug Resistance and Antibiotic Misuse In English.
Multiple Drug Resistance and Antibiotic Misuse In English.Education Front
ย 

More from Education Front (18)

Generic Software Process Models
Generic Software Process ModelsGeneric Software Process Models
Generic Software Process Models
ย 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
ย 
Problem Sloving
Problem SlovingProblem Sloving
Problem Sloving
ย 
Problem Solving - 1
Problem Solving - 1Problem Solving - 1
Problem Solving - 1
ย 
Process Models
Process ModelsProcess Models
Process Models
ย 
Process Models
Process ModelsProcess Models
Process Models
ย 
Revised Process of Communication
Revised Process of CommunicationRevised Process of Communication
Revised Process of Communication
ย 
Importance of Language in Communication
Importance of Language in CommunicationImportance of Language in Communication
Importance of Language in Communication
ย 
Lecture1 (SE Introduction)
Lecture1 (SE Introduction)Lecture1 (SE Introduction)
Lecture1 (SE Introduction)
ย 
Lecture 2 (Software Processes)
Lecture 2 (Software Processes)Lecture 2 (Software Processes)
Lecture 2 (Software Processes)
ย 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
ย 
Facing Todayโ€™s Communication Challenges
Facing Todayโ€™s Communication ChallengesFacing Todayโ€™s Communication Challenges
Facing Todayโ€™s Communication Challenges
ย 
Introduction To EMU
Introduction To EMUIntroduction To EMU
Introduction To EMU
ย 
Lecture 2: Facing Todayโ€™s Communication Challenges.
Lecture 2: Facing Todayโ€™s Communication Challenges.Lecture 2: Facing Todayโ€™s Communication Challenges.
Lecture 2: Facing Todayโ€™s Communication Challenges.
ย 
Effective communication skills
Effective communication skillsEffective communication skills
Effective communication skills
ย 
Introduction to Presentation Skills
Introduction to Presentation SkillsIntroduction to Presentation Skills
Introduction to Presentation Skills
ย 
Multiple Drug Resistance and Antibiotic Misuse in Urdu.
Multiple Drug Resistance and Antibiotic Misuse in Urdu.Multiple Drug Resistance and Antibiotic Misuse in Urdu.
Multiple Drug Resistance and Antibiotic Misuse in Urdu.
ย 
Multiple Drug Resistance and Antibiotic Misuse In English.
Multiple Drug Resistance and Antibiotic Misuse In English.Multiple Drug Resistance and Antibiotic Misuse In English.
Multiple Drug Resistance and Antibiotic Misuse In English.
ย 

Recently uploaded

Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
ย 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
ย 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
ย 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
ย 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
ย 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
ย 
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
ย 
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Call Girls in Nagpur High Profile
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
ย 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
ย 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7Call Girls in Nagpur High Profile Call Girls
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
ย 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
ย 

Recently uploaded (20)

Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
ย 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
ย 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
ย 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
ย 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
ย 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
ย 
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
ย 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
ย 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
ย 
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
ย 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
ย 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
ย 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
ย 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ย 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
ย 

Introduction To Stack

  • 1. Introduction To Stack By: Dr. Ghulam Rasool
  • 2. Stack โ€ข A variable sized data structure in which insertion or deletion is made just from one end or โ€ข A LIFO data structure is called Stack Operations on Stack 1) Push ( to insert an element into stack) 2) Pop( to take an element out of stack) The last element inserted is deleted or taken out first and first element at last The stack can be implemented using Array as well as Link List
  • 3. Stack using Arrays โ€ข The no of elements that can be inserted in a the stack is the dimension of array. The current position of stack(i.e its size is known by a pointer called its top. Algorithm to insert data in stack Push(S,Top, X, N) 1 If Top >= N then wrtie (โ€˜Stack fullโ€™) and exit 2 Top=Top+1 3 S[Top]= X 4 Exit
  • 4. Stack Operations Algorithm to delete an element from Stack Pop(S, Top) 1 If Top= 0 then write(โ€˜ stack is emptyโ€™) and exit 2 Pop = S[Top] 3 Top= Top-1 4 Exit Applications of Stack i) Recursion ii) Evaluation of Arithmetic expressions a) Infix notation b) prefix notations c) postfix notations
  • 5. Recursion โ€ข The calling of a subprogram to itself is called recursions Examples: Factorial of a number Fact(N) 1) If N= 0 then Fact =1 2) Fact= N* Fact(N-1) Polish Suffix notations โ€ข It is named after Polish mathematician Jan Lukasiewiez. The operator symbol is placed before its two operands in this notations โ€ข Examples: AB+, CD-, EF*
  • 6. PSN notations โ€ข The expressions in which operands are preceded by the operators are called PSN notations or postfix notations. โ€ข Example: Following are PSN notations AB+ DE* ABC*+ โ€ข Convert A+B*C into PSN Symbol scanned operator Stack PSN A A + + A B + AB * +* AB C +* ABC $ ABC *+
  • 7. RPN(Q, P) โ€ข Suppose Q is expression in infix form. This algorithm covert this expression into equivalent postfix expression P 1) Scan Q from left to right and repeat Steps 2 to 5 for each element of Q until the end of Expression 2) If an operand is encountered, add it to P 3) If a left parenthesis is encountered, push it onto stack 4) If an operator is 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 stack 5) 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 left parenthesis 6) Exit
  • 8. Quiz 1 โ€ข Q.1 What is difference b/w Stack and Array. Can a stack be an array and an array can be a stack? โ€ข Q.2 Convert following expressions into PSN ((A- (B+C)) *D)^(E+F)
  • 9. Assignment I Q.2 Write a program that should take infix expression and convert it into PSN. The program should also evaluate PSN expression.
  • 10. Algorithm for evaluation of PSN 1 Scan the Postfix string from left to right. 2 Initialise an empty stack. 3 Repeat step 4 until the end of string 4 If the scanned character is an operand, Push it to the stack. a) If the scanned character is an Operator, pop top two elements and apply operator. b) Push result back on top of stack 5 Pop last value from stack 5 Exit.
  • 11. Example โ€ข infix expression: 1+ 2 *3 โ€ข Postfix : 1 2 3 + * Symbol Stack 1 1 2 1, 2 3 1, 2, 3 + 1, 5 * 5
  • 12. Towers of Hanoi โ€ข Suppose three Pegs labled A, B and C and Suppose on Peg A there are placed a finite number n of disks with decreasing size. โ€ข The objective of game is to move the disks from Peg A to PegC using Peg B as an intermediate. โ€ข The rules of game are as: i) Only one disk may be moved at a time, specifically only the top disk on any Peg may be moved to any other Peg. ii) A larger disk can not be placed on a smaller disk โ€ข Example: For n=3 โ€ข Move top disk from A to C Move top disk from A to C โ€ข Move top disk from A to B Move top disk from B to A โ€ข Move top disk from C to B Move top disk from B to C โ€ข Move top disk from A to C
  • 13. Recursive Solution 1 Move top n-1 disks from A to B 2 Move the top disk from A to C 3 Move the top n-1 disks from B to C General notation: Tower(N, Beg, Sec, End) When N=1 Tower(1, Beg, Sec, End) When N>1 Tower( N-1 Beg, End, Sec) Tower(1, Beg, Sec, End) Beg โ€ฆ> End Tower( N-1, Sec, Beg, End)