• recategorized by
1,811 views
3 3 votes

What is the prefix expression corresponding to the expression:

$\left ( \left ( 9+8 \right ) \ast 7+\left ( 6\ast \left ( 5+4 \right ) \right )\ast 3\right )+2?$

You may assume that $\ast$ has precedence over $+$?

  1. $\ast + +\: 987 \ast \ast \: 6 + + \:5432$
  2. $\ast + + +\: 987 \ast \ast \: 6 + \:5432$
  3. $+ \ast + +\: 987 \ast \ast \: 6 + \:5432$
  4. $+ + \ast +\: 987 \ast \ast \: 6 + \:5432$
  5. $+ \ast + \ast \: 987+ + \: 6 \ast \:5432$

3 Answers

2 2 votes

Option (D) 

Given Infix Expression: ((9+8)∗7+(6∗(5+4))∗3)+2

We know that if an infix expression is a operator b, then the prefix expression will be operator a b.

Start converting to prefix

Solve the innermost brackets first.

((+98)*7+(6*(+54)*3)+2

Now, group the following and apply prefix operation.

((+98)*7+(6*(+54)*3)+2

We get

((*+987)+(*6+54)*3)+2

Now, group the following and apply prefix operation.

((*+987)+(*6+54)*3)+2

((*+987)+(**6+543)+2

Now, group the following and apply prefix operation.

((*+987)+(**6+543)+2

(+*+987**6+543)+2

Now, group the following and apply prefix operation.

(+*+987**6+543)+2

++*+987**6+5432 

Ans. Option (D)

1 1 vote
In the given infix expression $3$ types of the operator are used:

1 Parenthesis $()$ operator has the highest precedence over remaining and associativity is left to right.

2  $*$ has the highest precedence over the $+$ operator given both have associativity is left to right.

So the order of precedence in descending order: $()>*>+$

Infix-to-prefix conversation steps are as follows:

$((9+8)∗7+(6∗(5+4))∗3)+2$

$\implies (+98 * 7 +(6*(5+4))*3)+2$

$\implies  ((+98) * 7+ (6* (+54))*3)+2$

$\implies ((+98)*7 +(*6+54)*3)+2$

$\implies (*+987)+ (*6+54)*3+2$

$\implies (*+987)+ (**6+543)+2$

$\implies (+*+987**6+543)+2$

$\implies ++*+987**6+5432$

Option $(D)$ is correct.
• edited by
0 0 votes

Option $(D)$

Steps to convert Infix to Prefix:

$1.$ Reverse the Infix expression, replace ‘(’ with ‘)’ and vice-versa.

$2.$ Convert into Postfix expression.

$3.$ Reverse the postfix expression.

 

Reversed expression: $2+(3*((4+5)*6))+7*(8+9))$

 

Check here https://gateoverflow.in/2633/gate1995-2-21 to see how to convert infix to postfix expression.

 

Postfix expression using operator stack: $2345+6**789+*++$

Reverse the above postfix expression to get the prefix expression: $++*+987**6+5432$ 

 

Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
830
830 views
soujanyareddy13 asked Dec 7, 2021
830 views
$\text{ABC}{\ast}+$ is the postfix form of :$ \text{A}\;{\ast}\; \text{B} + \text{C} $$ \text{A}{\ast} + \text{BC} $$ \text{A} + \text{B}\;{\ast}\; \text{C} $none of thes...
2 2 votes
1 1 answer
1.4k
1.4k views
soujanyareddy13 asked Mar 25, 2021
1,433 views
Let $L$ be a singly-linked list $X$ and $Y$ be additional pointer variables such that $X$ points to the first element of $L$ and $Y$ points to the last element of $L$. Wh...
6 6 votes
3 3 answers
1.8k
1.8k views
admin asked Mar 30, 2020
1,819 views
Assume that the operators $+,-,\times$ are left associative and $\wedge$ is right associative. The order of precedence(from highest to lowest) is $\wedge,\times, +,-$. Th...
2 2 votes
2 answers 2 answers
5.0k
5.0k views
go_editor asked Jul 4, 2016
4,965 views
The postfix expression AB + CD -* can be evaluated using astacktreequeuelinked list