293 views
9 9 votes

Convert the following infix expression into postfix expression:

$$\texttt{a + (b - c) - d * ((e - f) / g + h)}$$

Which of the following is correct?

  1. $\texttt{a b c - + d e f - g / h + * -}$
     
  2. $\texttt{a b c - d e f - g / h + * - +}$
     
  3. $\texttt{a b + c - d e f - g / h + * -}$
     
  4. $\texttt{a b c - + d e f - g h + / * -}$

4 Answers

2 2 votes

First convert the bracketed parts:

$\texttt{(b - c)}\rightarrow$ $\texttt{b c -}$

$\texttt{(e - f)}\rightarrow$ $\texttt{e f -}$

$\texttt{(e - f) / g}\rightarrow$ $\texttt{e f - g /}$

$\texttt{((e - f) / g + h)}\rightarrow$ $\texttt{e f - g / h +}$

Now combine:

$\texttt{a + (b - c)}$

becomes:

$\texttt{a b c - +}$

And:

$\texttt{d * ((e - f)/g + h)}$

becomes:

$\texttt{d e f - g / h + *}$

So the complete postfix expression is:

$\texttt{a b c - + d e f - g / h + * -}$

Correct option : A

1 1 vote

do first all brackets bc- , ef- then ef-g/ 

then ef-g/h+ 

now for def-g/h+*

now add and subtraction have same associativity but from left to right so first addition will be formed 

so final A. a b c - + d e f - g / h + * -

Answer:
Position:
Show:

Related questions

8 8 votes
3 3 answers
289
289 views
GO Classes asked Jul 9
289 views
Consider the following postfix expression:$\texttt{1 2 3 + 4 5 * * +}$Which of the following fully parenthesized infix expressions is equivalent to it?$\texttt{( 1 + ( ( ...
6 6 votes
3 3 answers
247
247 views
GO Classes asked Jul 9
247 views
Convert the following fully parenthesized infix expression into postfix form:$\texttt{( 2 + ( ( 3 + 4 ) * ( 5 * 6 ) ) )}$Which of the following is the correct postfix exp...
6 6 votes
2 2 answers
257
257 views
GO Classes asked Jul 7
257 views
Which of the following statements is true about arithmetic expressions?Parentheses are needed in all arithmetic expressions. Infix expressions do not require precedence r...
5 5 votes
2 2 answers
235
235 views
GO Classes asked Jul 7
235 views
Which of the following permutations can be obtained in the same order using a stack, assuming the input sequence is:$$5, 6, 7, 8, 9$$$7, 8, 9, 5, 6$ $5, 9, 6, 7, 8$ $7, 8...