2,815 views

2 Answers

3 votes
3 votes

It will be O(n) only.

Method 1 :

It takes O(n) time to convert a infix expression into the postfix expression and only one left to right scan is enough to compute the value of the expression which will take O(n) again.

So totally its O(n).

Reference :

1]  http://geeksquiz.com/stack-set-2-infix-to-postfix/ & http://geeksquiz.com/stack-set-4-evaluation-postfix-expression/

2] http://faculty.cs.niu.edu/~hutchins/csci241/eval.htm


Method 2 :

Alternative to method 1, you can also go for evaluation using two stacks, Operator stack & Operand stack.

Check this for more reference : http://stackoverflow.com/questions/13421424/how-to-evaluate-an-infix-expression-in-just-one-scan-using-stacks

0 votes
0 votes
O(n)

Related questions

1 votes
1 votes
1 answer
1
2 votes
2 votes
1 answer
2
1 votes
1 votes
0 answers
4
iarnav asked Nov 19, 2017
649 views
To evaluate an expression with any embedded function call at any time how many stacks are needed?