2. Data structure
•The term refers to a data collection with
well defined operations and
behaviour or properties.
3. Stack
• It is a linear data structure implemented in LIFO
manner.
• LIFO-->LAST IN,FIRST OUT
• Insertions and deletions are restricted to occur only
at one end-stack's top.
• Stack is a dynamic structure.
• Dynamics means it grows with increase in number of
6. SOME TERMS RELATED TO STACK
Peek: refers to inspecting the value at the stack's top without
removing it.Also referred to as inspection.
Overflow:This is an error.It occurs when we try to push on a stack
which is already full.
Underflow: This error occurs when one tries to pop/delete item
from an empty stack.
7. Example of a stack
• Ques: Given a stack of capacity 4 which is initially empty,draw
pictures of the stack after each of the following stacks.Initially the
Stack is empty.
• (I) Stack is empty
15. POLISH STRINGS
• Polish strings ,named after a Polish mathematician ,Jan Lukaiewicz,
refers to the notation in which the operator symbol is placed either
before its operands or after its operands.
17. HOW TO
CONVERT AN
INFIX
EXPRESSION
TO POST FIX
EXPRESSION
We follow an evaluation order while converting an
infix expression to postfix expression .Evaluation
order is
1 . Brackets or Parenthesis
2. Exponentiation
3. Multiplication or Division
4. Addition or Subtraction
18. What if operators
of the same
priority are in
one expression
The operators with the
same priority are evaluated
from left to right.
19. Ways to
convert an infix
expression to
postfix
expression
1. Converting
Manually
01
2.Converting
using Stack
02
20. Steps for
Manual
Conversion
Determine
Determine the
actual evaluation
order by inserting
braces.
Convert
convert the
expression in the
innermost braces
into postfix
notation by
putting the
operator after the
operands.
Repeat
Repeat
step 2.until entire
expression is
converted
into post fix
notation.
21. Convert (A+B)*C/D into post fix expression
• Step1: Determine the actual evaluation order by inserting braces,
• So.. if we go from left to right ..after (A+B) evaluation(why A+B evaluated
first??.....because they are in parenthesis.
• So .after A+B EVALUATION ,* should be evaluated..
• Therefore expression now is
• ((A+B)*C)/D
22. ((A+B)*C)/D...SO NOW CONVERT IT INTO POST
FIX
• STEP1: evaluate innermost brackets first..
• So now it is: (AB+*C)/D
• NOW evaluate next level parenthesis
• AB+C*/D
• Now evaluate the last operator left
• AB+C*D/
23. Q.2 Convert
((A+B)*C/D+E^F
)/G INTO POST
FIX
INSERT PARENTHESIS
1. (A+B)*C/D+(E^F)/G
2.((A+B)*C)/D+(E^F)/G
3.(((A+B)*C)/D)+(E^F)/G
4.((((A+B)*C)/D)+(E^F))/G
27. EVALUATE NOT A OR NOT B AND NOT C
• In logical expression, preference of NOT is highest ,then comes the
preference of AND....OR has the least precedence
• ((NOT A) OR ((NOT B) AND (NOT C)))
• FIRST NOT'S WILL BE EVALUATED...
• THEN AND WILL BE EVALUATED
• AND THEN OR WILL BE EVALUATED
31. The steps are:
Repeat Repeat it till the end of the expression
Push back Push back the result of the evaluation.
Pop Pop the two operands from the stack,if the element is a
binary operator..In case of Unary operator,pop only one element.
Push Push the element in the stack if it is an operand.
Read Read the expression from left to right;
32.
33. Evaluate: true false true NOT false true OR NOT
AND OR AND
Read from left to right.
I. 'true' is operand; pushed into
stack
TRUE
46. Convert (TRUE and FALSE) or not(FALSE or
TRUE)
STEP SYMBOL STACK POSTFIX
EXPRESSION
DESCRIPTION
0. [
1. ( [( PUSH (
2. TRUE [( TRUE
3. and [(and TRUE PUSH and
4. FALSE [(and TRUE FALSE
5. ) [ TRUE FALSE and POP and
6. or [or TRUE FALSE and PUSH or
7. not [or not TRUE FALSE and
8. ( [or not( TRUE FALSE and
9. FALSE [or not( TRUE FALSE and
FALSE
10. or [or not(or TRUE FALSE