in DS recategorized by
2,751 views
2 votes
2 votes
Convert the infix to postfix and prefix expression
1) log3! ^log4 *log log 6/7*4!
2)log3!^sin 2*cos 3
in DS recategorized by
2.8k views

2 Answers

5 votes
5 votes
Best answer

ans of 1

selected by

4 Comments

ans of 2

0
0
* is the parent to log and ^ in your answer of 1 right ? so in the answer shouldn't it be like "...^6loglog*7/...." ?
0
0
can you tell me source where you find !>log....i think both are unary oparator and have equal precedence and associativity will be from right to left
0
0
Which evaluate first * or/
0
0
4 votes
4 votes

Here precedence of ^ is more than / and *

So, ^ will evaluate first.

Next * and / has same precedence

So, see their associativity next. / and * both left to right associative

Prefix Evaluation

1) log3! ^log4 *log log 6/7*4!

=> ^log3!. log4 *log log 6/7*4!

=>*^log3! log4 loglog6 /7*4!

=> /*^log3! log4 loglog6 7*4!

=>*/*^log3! log4 loglog6 74!

2) log3!^sin 2*cos 3

=>^ log3!sin 2*cos 3

=>*^ log3!sin 2 cos 3

Similarly we can do Postfix too

4 Comments

@Srestha, I am getting -

 1) (log3! ^log4 )*(log log 6/7*4!)

Prefix -    * ^ log ! 3 log 4 log log / 6 * 7 ! 4

Postfix -   3 ! log 4 log ^ 6 7 4 ! * / log log *

where binary operator - " * " , "/ " .

          Unary operator - " log " , " ! (factorial) "

          operands = "3" , "4" , "6" , "7".
0
0
See why I am not considering ! as a symbol

because log 3! itself a value means log 6 and when u changing it's position it causes symbol as a whole operation u have done before. So, it causes error in result
0
0
See, So far we have seen algo for an expression where operator are only binary type, but think if we do little modification in that algo - like if we check type of operator ... if it is binary then pop 2 elements from stack and push (pop1 <binary-operator> pop2) and if it is unary then pop only one element and push ( <unary-operator > pop1 ) ....  So can't we do like this --- ??
0
0

Check this http://faculty.washington.edu/jstraub/dsa/aexp/

One example is given here.

0
0

Related questions