Skip to main content
Logo image

Problem Solving with Algorithms and Data Structures using Kotlin The Interactive Edition

Section 7.10 Trees: Exercises

Exercises Exercises

1.

Trace the algorithm for creating an expression tree for the expression \((4 * 8) / 6 - 3\text{.}\)

2.

Consider the two different techniques we used for implementing traversals of a binary tree. Why must we check before the call to preorder when implementing it as a method, whereas we could check inside the call when implementing it as a function?

4.

Extend the buildParseTree method to handle mathematical expressions that do not have spaces between every character.

5.

Modify the buildParseTree and evaluate methods to handle Boolean statements (&&, ||, and !). Remember that ! is a unary operator, so this will complicate your code somewhat.

6.

Clean up the expressionToString method so that it does not include an extra set of parentheses around each number.

7.

Write a method that takes a parse tree for a mathematical expression and calculates the derivative of the expression with respect to some variable.
You have attempted of activities on this page.