Question

State the pseudo code and worst case running time to evaluate a prefix evaluation using a...

State the pseudo code and worst case running time to evaluate a prefix evaluation using a stack data structureState the pseudo code and worst case running time to evaluate a prefix evaluation using a stack data structure

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Algorithm to evaluate prefix-expression

Step 1: start traversing expression from right to left
Step 2: If character at current position is an operand push it to Stack
Step 3: If the character at current position is an operator pop two operands from the Stack. Operate on these operands
according to the operator, and push the result to the Stack

Step 4: goto step-2 if complete expression is not traversed(or we reached at left end of expression).

finally,print value at the top of stack will give result of expression.

since we scan the expression once(right to left) and perform O(N) push(take O(1) time) and pop operations (take O(1) time)in worst case .

Therefore overall complexity = O(N)

Add a comment
Know the answer?
Add Answer to:
State the pseudo code and worst case running time to evaluate a prefix evaluation using a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT