Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— Presentation transcript:

1 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:

2

3

4 STEP WISE EVALUATION OF 636+5*9/-

5 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)

6

7 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

8 APPLICATION OF RECURSION: 1.computing factorial of a given number. 2.finding the Fibonacci series. 3.deter­mining the GCD (Greatest Common Divisor) of two positive numbers. 4.computing binary equivalent of a decimal number. 5.towers of Hanoi problem.


Download ppt "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,"

Similar presentations


Ads by Google