in DS edited by
3,412 views
4 votes
4 votes

The infix expression $A+(B-C)^*D$ is correctly represented in prefix notation as

  1. $A+B-C^*D$
  2. $+A^*-BCD$
  3. $ABC-D^*+$
  4. $A+BC-D^*$
in DS edited by
3.4k views

2 Answers

6 votes
6 votes
Best answer

Option B 

Scan Right to Left

Stack : * ) -

Pop - ) by seeing (

Stack: *

Pop * as incoming is +

Stack : +

Output : +A*-BCD

selected by
5 votes
5 votes

(  ) has highest priority then * then +.

so whatever inside the bracket will be evaluated first

A+(−BC) *D

A+((−BC) *D))

A+(*−BCD)

(A+(*−BCD))

+A*−BCD

OPTION B

by