Algorithm to evaluate expressions using prefix notation

Assignment Help Data Structure & Algorithms
Reference no: EM131052566

Algorithm To Evaluate Expressions Using Prefix Notation.

Initialization:

1. Read a token from the input stream.

a. If it is an operand, push it into the operand stack.

b. If it is an operator, push a marker onto operand stack and push the actual operator onto operator stack.

Loop While (there are more input tokens):

1. Read a token.

2. If token is an operator, push operator onto operator stack and push the marker onto operand stack.

3. Else if, the token is an operand, check the top of the operand stack for a marker.

a. If the marker is on top of the stack, push the read operand onto the operand stack.

b. Else If - the top of the operand stack contains another operand:

Loop While (the top of the stack is an operand):

1. Pop operand from operand stack.

2. Pop marker from operand stack and the corresponding operator from the operator stack.

3. Apply the operation on the read token and popped operand and obtain result.

4. 1 If the top of the stack is another operand, continue Looping (as stated above in Loop While constraint).

4.2 Else if the top of the stack is an operator or the operand stack is empty, push the result and exit the loop.

4. Go back to step 1 (loop)

Loop is finished:

When the loop is finished (all of the input has been read), the value on top of the operand stack is the result of evaluating an expression using the prefix notation.

Some possible errors:

The operand stack was not empty at the end of algorithm.

The operator stack was not empty at the end of algorithm.

An operator is the last token in the input.

Reading illegal token from the input.

Reference no: EM131052566

Questions Cloud

Depreciation for income tax purposes : To determine the amount to be used for depreciation for income tax purposes the owner used the assessment figures as a basis for his calculations. Which of the following most nearly reflects the depreciable amount? Show your work.
Income statement that reduces equity via retained earnings : Why do capital expenditures increase assets while other cash outflows, like paying salary, taxes, etc., do not create any asset, and instead instantly create an expense on the income statement that reduces equity via retained earnings? Explain in ..
Expense-liabilities-revenue-net assets and assets : Transactions and financial statements (accrual basis) for the month of December 2014. Using only five accounts – Expense, Liabilities, Revenue, Net assets and Assets – record the following transactions and prepare a balance sheet and statement of ope..
How nats rebellion affect relation between north and south : How did Nat's rebellion affect the relationship between the North and South? Think about what happened to the trust between them.
Algorithm to evaluate expressions using prefix notation : Algorithm To Evaluate Expressions Using Prefix Notation. Initialization: Read a token from the input stream. If it is an operand, push it into the operand stack. If it is an operator, push a marker onto operand stack and push the actual operator onto..
Describe the economy of your state : What explanations have been offered in the press? How accurate are they?
German stock traded on the frankfurt exchange : Erin McQueen purchased 50 shares of BMW, a German stock traded on the Frankfurt Exchange, for 64.5 euros (€) per share exactly 1 year ago when the exchange rate was 0.67 €/US$. Today the stock is trading at 71.8 (€) per share, and the exchange rate i..
Infrastructure overhead of implementing strategy process : Why do many organizations choose not implement this process? Do you believe the cost and infrastructure overhead of implementing the Orion Strategy Process is worth the benefits? Why or why not? Without performing all of the steps within the Orion St..
Requirements of the hazard communication standard : List and briefly discuss four exceptions to the Safety Data Sheet (SDS) requirements of the Hazard Communication Standard (HCS).

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  If you can monitor when sql injections are performed on an

if you can monitor when sql injections are performed on an sql database what would you recommend as a security

  What is global or per process page replacement algorithms

What is better global or per process page replacement algorithms?

  Finding the values of queuefront and queuerear

Assume that queue is a queue type object and the size of the array-implementing queue is 100. Also, assume that the value of the queueFront is 25 and the value of queueRear is twenty-five.

  Database design process

A college course may have one or more scheduled sections, or may not have a scheduled section. Attributes of COURSE include Course_ID, Course_Name, and Units.

  Evaluate each of the following statements

If x = 5, y = 6, z = 4, and w = 3.5, evaluate each of the following statements, if possible. If it is not possible, state the reason.

  Algoithm to select to describe intrinsically recursive

Algoithms you select so you can describe and assess them. Write challenges did you face in process? How did you go about resolving them?

  Recognize how many playing cards you have

Create a flowchart that programs a robot to recognize how many playing cards you have and to put them in order from smallest to largest.

  Give the steps to build priority queue in heap structure

Both are given from a paper assignment both are Logic questions. I don't need ANY CODE AT ALL. Just the general steps you would use.

  Using java, design and implement an api euclidean graph

Using Java, design and implement an API EuclideanGraph for graphs whose vertices are points in the plane that include coordinates.

  Various search trees and numerous sorting techniques

This week we were introduced to various search trees and numerous sorting techniques. Taking into consideration what you have learned this week, discuss how you can help Bob with his problem.

  Illustrate how b-tree will expand

Illustrate how tree will expand (after inserting each Part#), and what the final tree would like. (b) Repeat item (a), but use a B-tree of order p = 4 instead of a B+-tree.

  Write a function to insert a node after the head

In a doubly-lined list, each node points to both the next and previous nodes. The info in the each node is an integer and two pointers, one to the previous node and one to the next node - Define the node

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd