Transcript File

5.3 EVALUATION OF POSTFIX EXPRESSION
 For example, consider the evaluation of the following postfix
expression using stacks:
abc+d*f/- where,
 a=6, b=3, c-6, d=5, f=9 After substituting the values of a, b,
c, d and f, the postfix expression becomes 636+5*9/ The expression is evaluated as follows:
STEP WISE EVALUATION OF 636+5*9/-
EXAMPLE:
 Evaluate Following Postfix Expression:
(1)A*B+C/D (if A=3,B=2,C=25,D=5) using stack.
(2)AB+C*D(if A=2,B=3,C=4,D=5)( assume + after D)
(3)562+*124/(4)ABC^/DE*+AC*-(A=27,B=3,C=2,D=3,E=17)
(5)76 + 4 * 410 - ^ 5 +
(6) 75 – 9 2 / * (ANS: 9.00)
5.5 RECURSION
 When a function definition includes a call to itself, it is
referred to as a recursive function and the process is
known as recursion or circular definition.
 In each recursive call, the current values of the parameters, local
variables and the return address where the control has to return
from the call are required to be stored. For storing all these
values, a stack is maintained.
 When a recursive function is called for the first time, a space is set
aside in the memory to execute this call and the function body is
executed. Then a second call to the function is made; again a space
is set for this call and so on. These memory areas for each function
call are arranged in the stack. Each time the function is called, its
memory area is placed on the top of the stack and is removed
when the execution of the call is completed
APPLICATION OF RECURSION:
1.
2.
3.
4.
5.
computing factorial of a given number.
finding the Fibonacci series.
determining the GCD (Greatest Common Divisor) of two positive numbers.
computing binary equivalent of a decimal number.
towers of Hanoi problem.