Java Reference
In-Depth Information
Output
Enter an expression: 3+4*5
3+4*5=23
S ELF C HECK
9. What is the difference between a term and a factor? Why do we need
both concepts?
10. Why does the expression parser use mutual recursion?
11. What happens if you try to parse the illegal expression 3+4*)5 ?
Specifically, which method throws an exception?
CHAPTER SUMMARY
1. A recursive computation solves a problem by using the solution of the same
problem with simpler values.
2. For a recursion to terminate, there must be special cases for the simplest values.
3. Sometimes it is easier to find a recursive solution if you make a slight change
to the original problem.
4. Occasionally, a recursive solution runs much slower than its iterative counter
part. However, in most cases, the recursive solution is only slightly slower.
5. In many cases, a recursive solution is easier to understand and implement
correctly than an iterative solution.
6. In a mutual recursion, a set of cooperating methods calls each other repeatedly.
617
618
REVIEW EXERCISES
ΞΆ Exercise R13.1. Define the terms
a. Recursion
b. Iteration
Search WWH ::




Custom Search