Evaluating an integer expression tree

Assignment Help Data Structure & Algorithms
Reference no: EM132412767

Exercise

A binary expression tree is a special type of binary tree that is used to represent expressions. A binary expression tree's leaves are operands, like constants or variable names, and other nodes contain operations. An expression tree can be evaluated applying the operator at the root to the values obtained by recursively evaluating the left and right subtrees.

447_binary tree.jpg

The objective of this exercise is to implement an algorithm that is capable of evaluating an integer expression tree. All tree operators will have zero or two children. Integer values will appear in leaf nodes, whereas internal nodes will contain operators. In order to evaluate a tree of this kind, you can use the following recursive approach:

Let t be the expression tree If t is not null then
If t.value is operand then Return t.value
Else
A = solve (t.left) B = solve(t.right)
Return (A operator B)

You will find a code skeleton in edu.uoc.mecm.eda.bet.ExpressionTreeEvaluator that you will have to modify in order to achieve your objective.

Note that the tree constructor expects a postfix input expression which you will have to use to build the tree. In order to do so, you should use a stack as follows:

While there are characters in the postfix input expression Let c be the input character
Let t be a new tree node t = new node (c)
If c is an operand then Push (t)
Else
A = Pop() B = Pop()
t.right = A t.left = B Push (t)
At the end, the stack's last element is the tree's root node

Once you have completed the implementation, you can check it against the unit tests you can find in the ExpressionTreeEvaluatorTest class.

Reference no: EM132412767

Questions Cloud

Observational study on human behavior : Several years ago, an article was published that described an observational study on human behavior. Researchers observed 525 men and 475 women at bus stops
How you have grown in the areas of educational theory : In this assignment, you will write a reflective synthesis statement that examines your development and growth throughout the program and plans for the future.
Developing truly suitable tests : The study of IQ is complicated by numerous problems including difficulty in developing truly suitable tests, problems in interpreting results, and applying
Crossed with a pure-breeding wild type male : If a female pure-breeding white eyed female is crossed with a pure-breeding wild type male, what offspring would you expect to see in the F1 generation?
Evaluating an integer expression tree : Implement an algorithm that is capable of evaluating an integer expression tree. All tree operators will have zero or two children
Role of homologous chromosomes in sexual reproduction : In your answer, you must define homologous chromosomes and explain why they are necessary for successful sexual reproduction.
Explain how checkpoints serve to regulate the cell cycle : Explain how checkpoints serve to regulate the cell cycle and help a cell avoid mutations and cancer (when working properly, of course!).
Symbiotic relationships between biotic and abiotic parts : Have human activities affected these areas in any way? How? what is the symbiotic relationships between biotic and abiotic parts in these specific biomes
Define carrying capacity : Define carrying capacity and then apply it to the following two ecosystems: (1) Tropical Rainforest and (2) Desert. Choose one specific geographic location

Reviews

len2412767

12/7/2019 12:00:08 AM

must use Java and be run in intellij Idea Exercises 3 and 4 are worth 30% each. In these exercises the correctness of the source code (passing all available unit tests – without changing them in any way), the most appropriate data structure choice, the justification for your choice and the code’s legibility will be evaluated.

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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