Question

In: Computer Science

the postfix notation for (7-4)+2 is

the postfix notation for (7-4)+2 is

Solutions

Expert Solution

Solution:

So the final postfix is : 74-2+

Let, X is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression Y.

  1. Push “(“onto Stack, and add “)” to the end of X.
  2. Scan X from left to right and repeat Step 3 to 6 for each element of X until the Stack is empty.
  3. If an operand is encountered, add it to Y.
  4. If a left parenthesis is encountered, push it onto Stack.
  5. If an operator is encountered ,then:
    1. Repeatedly pop from Stack and add to Y each operator (on the top of Stack) which has the same precedence as or higher precedence than operator.
    2. Add operator to Stack.
      [End of If]
  6. If a right parenthesis is encountered ,then:
    1. Repeatedly pop from Stack and add to Y each operator (on the top of Stack) until a left parenthesis is encountered.
    2. Remove the left Parenthesis.
      [End of If]
      [End of If]
  7. END.

Related Solutions

CS 209 Data Structure (Postfix notation) Postfix notation is a way of writing expressions without using...
CS 209 Data Structure (Postfix notation) Postfix notation is a way of writing expressions without using parentheses. For example, the expression (1 + 2) * 3 would be written as 1 2 + 3 *. A postfix expression is evaluated using a stack. Scan a postfix expression from left to right. A variable or constant is pushed into the stack. When an operator is encountered, apply the operator with the top two operands in the stack and replace the two...
Skills needed to complete this assignment: linked lists, stacks. Postfix notation, is a mathematical notation in...
Skills needed to complete this assignment: linked lists, stacks. Postfix notation, is a mathematical notation in which operators follow their operands; for instance, to add 3 and 4, one would write 3 4 + rather than 3 + 4 (infix notation). If there are multiple operations, operators are given immediately after their second operands; so, the expression written 3 − 4 + 5 in conventional notation would be written 3 4 − 5 + in postfix notation: 4 is first...
(Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses....
(Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses. For example, the expression ( 11 + 12 ) * 13 would be written as 11 12 + 13 * Assume that ALWAYS there is a space between operands and operators in the input expression. Use two stacks, one to store the operands and one to store the operators. Your program only accpets following operators : ( ) + - / * Write a...
Using Java 8. Write a program that reads an expression in postfix notation, builds the expression...
Using Java 8. Write a program that reads an expression in postfix notation, builds the expression tree and prints the expression in prefix and infix notation and evaluates the expression. (Hint use a stack)
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2...
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2 + 5 * 8 4 / - The program should read a postfix expression consisting of single digits and operators into a StringBuilder, The program should read the expression and evaluate it (assume it's valid). The algorithm to evaluate a postfix expression is shown below. Use +, -, *, /, and ^. ^ is the exponent. Append a right parenthesis ') ' to the...
A=[ 7 8 -2 -6 7 4 1 ; 2 4 -4 -13 9 9 -12...
A=[ 7 8 -2 -6 7 4 1 ; 2 4 -4 -13 9 9 -12 ; 6 6 0 -9 8 9 -4 ; 1 8 -14 -22 5 8 -1 ; 4 9 -10 -14 7 4 -1] B=[ 19 4 4 14 -3 -7 -5 ; 21 -6 -5 10 14 -2 4 ; 22 -4 5 13 5 -6 4 ; 41 20 0 26 11 -1 -27 ; 29 14 -2 20 3 -4 -19]...
1) Consider the following infix expressions. What is the equivalent postfix (reverse Polish notation) expression? 16/(5+3)b)...
1) Consider the following infix expressions. What is the equivalent postfix (reverse Polish notation) expression? 16/(5+3)b) A*B+C*Dc) X × Y + W × Z + V × U 2) Consider the postfix (reverse Polish notation) 10 5 + 6 3 - /. What is the equivalent infix expression?
Mother's age 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,51 Female 1, 0, 2, 2, 3, 4, 7, 3, 2, 4, 7, 1,...
Mother's age 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,51 Female 1, 0, 2, 2, 3, 4, 7, 3, 2, 4, 7, 1, 6, 4, 5, 3, 1, 4, 0, 1, 1, 1, 0, 1, 0 Use the stem and leaf plots that you previously created to help you draw and label histograms on your scratch paper with bin width of 2 for mothers's age at birth of female students and for mother's age at birth of male students. Make the lower bound of your first bin...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
Step 2 Data Set A x 1 2 3 4 5 6 7 y 7 7...
Step 2 Data Set A x 1 2 3 4 5 6 7 y 7 7 7 9 9 9 10 Data Set B x 1 2 3 4 5 6 7 8 9 10 11 y 4 6 6 6 8 9 9 9 10 10 10 Step 2 Find the equation for the least-squares line, and graph the line on the scatter plot. Find the sample correlation coefficient r and the coefficient of determination r2. Is r significant?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT