You are on page 1of 14

19AIE111 Data Structure and Algorithms 1 (3-1-0-4)

S2 B.Tech CSE(AI)
Week 3 Lecture 2 STACK ADT
Another application of stack

Evaluation of Postfix expression:


Algorithm for Post fix Evaluation
• Algorithm Post fix Evaluation(P){ // P- Post fix Expression
• n= length(p)
for(i=0 n) {
if an operand is encountered , Push it onto to stack
if an operator X is encountered. Then
Remove two elements of stack,
• A- stack top element, B- next to stack top element.
Push (Evaluate B X A)
} Time complexity= O(n), n is the
} expression length .
Example the given postfix expression 5, 6, 2 ,+ ,* ,12, 4,
/, -
Example 2:Evaluate the given postfix expression
• Revision on Stacks
Question 1
• Write an algorithm using stack to check whether a string is
palindrome or not.

• Logic :
Question 2
• What will be the stack contents after function Find- Me() completes
it’s execution?
Convert the following infix expression to postfix
expression and evaluate the postfix expression

• Postfix expression:

• Postfix expression evaluates to


Overview
• STACK and it’s application. In all the topics Algorithm analysis part is
default)
• Balancing parenthesis
• Expression conversion and evaluation.
• Online exam( Quiz) on 24th March Wednesday during lab time.
• Coding exam( For Programming assignment 1) and Online exam(
Quiz) on 31st March Wednesday During lab time.
• Topic: STACK ADT and applications;
• All the three exams count for the internals.
• Pgm 1 : Stack
• Pgm 2: Queue+ Linked List+ Leetcode problems
• Pgm 3: Linked List
• Pgm4: : Trees
• Pgm 5 : Trees
Exam Calendar

You might also like