Skip to main content
Contents Index
Search Book
Search Results:
No results.
Read aloud
Readability settings Prev Up Next Scratch ActiveCode Profile
title here
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
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?
3.
Show the function calls needed to build the following binary tree.
Figure 7.10.1. Binary tree example
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.