## Exercises
#### Section B.1
1. Use induction to verify the candidate solution to each of the following recurrence equations.
1. *tn* = 4*t**n* − 1 for *n* > 1
*t*1 = 3
The candidate solution is *tn* = 3(4*n* − 1).
2. *tn* = *t**n* − 1 + 5 for *n* > 1
*t*1 = 2
The candidate solution is *t**n* = 5*n* − 3.
3. *t**n* = *t**n* − 1 + *n* for *n* > 1
*t*1 = 1
The candidate solution is *tn* = 3 (4*n*-1)
4. *t**n* = *t**n* − 1 + *n*2 for *n* > 1
*t*1 = 1
The candidate solution is ![](https://box.kancloud.cn/2e4ac323875404b8fdcbeffd3a4ccff6_190x47.jpg)
5. ![](https://box.kancloud.cn/70c1884a82a7b9bf715b416ebf47c175_313x48.jpg)
*t*1 = ½
The candidate solution is ![](https://box.kancloud.cn/ffe21441cc512c6cd6b097c9b8eb07d2_111x46.jpg)
6. *t**n* = 3*t**n* − 1 + 2*n* for *n* > 1
*t*1 = 1
The candidate solution is *t**n* = 5 (3*n* − 1) − 2*n* + 1.
7. *t**n* = 3*t**n*/2 + *n* for *n* > 1, *n* a power of 2
*t*1 = ½
The candidate solution is ![](https://box.kancloud.cn/c0aac28ed06dfca82624344756ee91ef_133x25.jpg)
8. *t**n* = *nt**n* − 1 for *n* > 0
*t*0 = 1
The candidate solution is *tn* = *n*!.
2. Write a recurrence equation for the *n*th term of the sequence 2, 6, 18, 54, …, and use induction to verify the candidate solution *sn* = 2 (3*n*-1).
3. The number of moves (*mn* for *n* rings) needed in the Towers of Hanoi problem (see Exercise 17 in [Chapter 2](LiB0014.html#141)) is given by the following recurrence equation
![](https://box.kancloud.cn/78b74168c76d198b1baa3648f8bc205c_243x46.jpg)
Use induction to show that the solution to this recurrence equation is *mn* = 2*n* - 1.
4. The following algorithm returns the position of the largest element in the array *S*. Write a recurrence equation for the number of comparisons *tn* needed to find the largest element. Use induction to show that the equation has the solution *tn* = *n* - 1.
```
index max_position (index low, index high)
{
index position;
if (low == high)
return low;
else{
position = max_position (low + 1, high);
if (S[low] > S[position])
position = low;
return position;
}
}
```
The top-level call is
*max\_position* (1, *n*).
5. The ancient Greeks were very interested in sequences resulting from geometric shapes such as the following traingular numbers:
![](https://box.kancloud.cn/61564b00cc3a5a240cf2fb69da560b37_292x53.jpg)
Write a recurrence equation for the *n*th term in this sequence, guess a solution, and use induction to verify your solution.
6. Into how many regions do *n* lines divide a plane so that every pair of lines intersect, but no more than two lines intersect at a common point? Write a recurrence equation for the number of regions for *n* lines, guess a solution for your equation, and use induction to verify your solution.
7. Show that ![](https://box.kancloud.cn/0ebab3cce21a90c1bb5044ec680808d0_152x46.jpg) is the solution to the following recurrence equation:
![](https://box.kancloud.cn/9a83b3498fa11362564897da1bdeb88e_400x67.jpg)
8. Write and implement an algorithm that computes the value of the following recurrence, and run it using different problem instances. Use the results to guess a solution for this recurrence, and use induction to verify to your solution.
![](https://box.kancloud.cn/2ab91c360d4051e1b9bab67492bf3794_257x46.jpg)
#### Section B.2
1. Indicate which recurrence eqations in the problems for [Section B.1](LiB0102.html#1371) fall into each of the following categories.
1. Linear equations
2. Homogeneous equations
3. Equations with constant coefficients
2. Find the characteristic equations for all of the recurrence equations in [Sections B.1](#ap-blev3sec1) that are linear with constant coefficients.
3. Show that if *f* (*n*) and *g* (*n*) are both solutions to a linear homogeneous recurrence equation with constant coefficients, then so is *c* × *f* (*n*) + *d × g* (*n)*, where *c* and *d* are constants.
4. Solve the following recurrence equations using the characteristic equation.
1. ![](https://box.kancloud.cn/6761ba15b0621c7ae25939e61a0ddd95_262x68.jpg)
2. ![](https://box.kancloud.cn/19e8ba0eb6a0c5980acf617ac0e406e1_301x72.jpg)
3. ![](https://box.kancloud.cn/a0fe9f88ec51978c4360cc38bc995045_305x75.jpg)
4. ![](https://box.kancloud.cn/4955cb004e2acb44b5e7fc37c75ed8a2_384x75.jpg)
5. Complete the solution to the recurrence equation given in [Example B.15](LiB0103.html#1410).
6. Complete the solution to the recurrence equation given in [Example B.16](LiB0103.html#1412).
7. Solve the following recurrence equations using the characteristic equation.
1. ![](https://box.kancloud.cn/4f56a13572a0919665daaf8e76dea386_261x72.jpg)
2. ![](https://box.kancloud.cn/e6ef22bfe63333103164ea4b28f28736_328x97.jpg)
3. ![](https://box.kancloud.cn/6fcf1aed581b5cab9692abeac46f1b71_333x71.jpg)
4. ![](https://box.kancloud.cn/ffe2cf12631e4370e2cc78301bb845b7_380x73.jpg)
8. Complete the solution to the recurrence equation given in [Example B.17](LiB0103.html#1414).
9. Show that the recurrence equation
![](https://box.kancloud.cn/9309bef52382df30735cb3a8828baedb_358x74.jpg)
can be written as
![](https://box.kancloud.cn/e672e67f68de00534d10af97377eb418_265x47.jpg)
10. Solve the recurrence equation in Exercise 17. The solution gives the number of derangements (nothing is in its right place) of *n* objects.
11. Solve the following recurrence equations using the characteristic equation.
1. ![](https://box.kancloud.cn/246b8ace31929e60e80747b6a19c2e6d_400x56.jpg)
2. ![](https://box.kancloud.cn/da7ab6f798b16b7f7443b6bf9dfd7241_400x58.jpg)
3. ![](https://box.kancloud.cn/595be313beef4bec9dd05b4c32400a39_345x47.jpg)
4. ![](https://box.kancloud.cn/4908d7410fd63f895ffd9eecf9bc0faa_400x60.jpg)
5. ![](https://box.kancloud.cn/3cf5e4a61a4cfb7919edb6c9cbc66bb9_384x50.jpg)
#### Section B.3
1. Solve the recurrence equations in Exercise 1 using the substitution method.
#### Section B.4
1. Show that
1. *f* (*n*) = *n*3 is a strictly increasing function.
2. *g* (*n*) = 2*n*3 - 6*n*2 is an eventually nondecreasing function.
2. What can we say about a function *f* (*n*) that is both nondecreasing and nonincreasing for all values of *n*?
3. Show that the following functions are smooth.
1. *f* (*n*) = *n* lg *n*
2. *g* (*n*) = *nk*, for all *k* ≥ 0.
4. Assuming in each case that *T* (*n*) is eventually nondecreasing, use [Theorem B.5](LiB0105.html#1438) to determine the order of the following recurrence equations.
1. ![](https://box.kancloud.cn/0c9b433dd4403828f4fec09694c95cf1_400x59.jpg)
2. ![](https://box.kancloud.cn/260a13831ab65927e8e5c9c8f36294a0_400x57.jpg)
3. ![](https://box.kancloud.cn/28ec64b189f3af7c2fcf6620d9a8881c_400x56.jpg)
5. Assuming in each case that *T* (*n*) is eventually nondecreasing, use [Theorem B.6](LiB0105.html#1443) to determine the order of the following recurrence equations:
1. ![](https://box.kancloud.cn/631410b8cd15a5fc4d4eebd5f6ecd8ce_400x57.jpg)
2. ![](https://box.kancloud.cn/61e9acb4386ff49bcf10a054ab84ff3c_400x58.jpg)
6. We know that the recurrence
![](https://box.kancloud.cn/f4978ccd1293d67d8027481f867675f5_400x60.jpg)
has solution
![](https://box.kancloud.cn/f352fdd4593defb3cc83e54e5d8894dd_145x26.jpg)
in the case *a* > *c*, provided that *g* (*n*) ∊ Θ (*n*). Prove that the recurrence has the same solution if we assume that
![](https://box.kancloud.cn/92fc4a08832fe721ec4e27e28b03d17e_255x25.jpg)
- Table of Contents
- BackCover
- Foundations of Algorithms Using C++ Pseudocode, Third Edition
- Preface
- Chapter Contents
- Pedagogy
- Course Outlines
- Acknowledgments
- Errors
- Chapter 1: Algorithms - Efficiency, Analysis, and Order
- 1.2 The Importance of Developing Efficient Algorithms
- 1.3 Analysis of Algorithms
- 1.4 Order
- 1.5 Outline of This Book
- Exercises
- Chapter 2: Divide-and-Conquer
- 2.1 Binary Search
- 2.2 Mergesort
- 2.3 The Divide-and-Conquer Approach
- 2.4 Quicksort (Partition Exchange Sort)
- 2.5 Strassen's Matrix Multiplication Algorithm
- 2.6 Arithmetic with Large Integers
- 2.7 Determining Thresholds
- 2.8 When Not to Use Divide-and-Conquer
- Exercises
- Chapter 3: Dynamic Programming
- 3.1 The Binomial Coefficient
- 3.2 Floyd's Algorithm for Shortest Paths
- 3.3 Dynamic Programming and Optimization Problems
- 3.4 Chained Matrix Multiplication
- 3.5 Optimal Binary Search Trees
- 3.6 The Traveling Salesperson Problem
- Exercises
- Chapter 4: The Greedy Approach
- 4.1 Minimum Spanning Trees
- 4.2 Dijkstra's Algorithm for Single-Source Shortest Paths
- 4.3 Scheduling
- 4.4 Huffman Code
- 4.5 The Greedy Approach versus Dynamic Programming: The Knapsack Problem
- Exercises
- Chapter 5: Backtracking
- 5.2 The n-Queens Problem
- 5.3 Using a Monte Carlo Algorithm to Estimate the Efficiency of a Backtracking Algorithm
- 5.4 The Sum-of-Subsets Problem
- 5.5 Graph Coloring
- 5.6 The Hamiltonian Circuits Problem
- 5.7 The 0-1 Knapsack Problem
- Exercises
- Chapter 6: Branch-and-Bound
- 6.1 Illustrating Branch-and-Bound with the 0 - 1 Knapsack problem
- 6.2 The Traveling Salesperson Problem
- 6.3 Abductive Inference (Diagnosis)
- Exercises
- Chapter 7: Introduction to Computational Complexity - The Sorting Problem
- 7.2 Insertion Sort and Selection Sort
- 7.3 Lower Bounds for Algorithms that Remove at Most One Inversion per Comparison
- 7.4 Mergesort Revisited
- 7.5 Quicksort Revisited
- 7.6 Heapsort
- 7.6.1 Heaps and Basic Heap Routines
- 7.6.2 An Implementation of Heapsort
- 7.7 Comparison of Mergesort, Quicksort, and Heapsort
- 7.8 Lower Bounds for Sorting Only by Comparison of Keys
- 7.8.1 Decision Trees for Sorting Algorithms
- 7.8.2 Lower Bounds for Worst-Case Behavior
- 7.8.3 Lower Bounds for Average-Case Behavior
- 7.9 Sorting by Distribution (Radix Sort)
- Exercises
- Chapter 8: More Computational Complexity - The Searching Problem
- 8.1 Lower Bounds for Searching Only by Comparisons of Keys
- 8.2 Interpolation Search
- 8.3 Searching in Trees
- 8.4 Hashing
- 8.5 The Selection Problem: Introduction to Adversary Arguments
- Exercises
- Chapter 9: Computational Complexity and Interactability - An Introduction to the Theory of NP
- 9.2 Input Size Revisited
- 9.3 The Three General Problem Categories
- 9.4 The Theory of NP
- 9.5 Handling NP-Hard Problems
- Exercises
- Chapter 10: Number-Theoretic Algorithms
- 10.1 Number Theory Review
- 10.2 Computing the Greatest Common Divisor
- 10.3 Modular Arithmetic Review
- 10.4 Solving Modular Linear Equations
- 10.5 Computing Modular Powers
- 10.6 Finding Large Prime Numbers
- 10.7 The RSA Public-Key Cryptosystem
- Exercises
- Chapter 11: Introduction to Parallel Algorithms
- 11.1 Parallel Architectures
- 11.2 The PRAM Model
- Exercises
- Appendix A: Review of Necessary Mathematics
- A.2 Functions
- A.3 Mathematical Induction
- A.4 Theorems and Lemmas
- A.5 Logarithms
- A.6 Sets
- A.7 Permutations and Combinations
- A.8 Probability
- Exercises
- Appendix B: Solving Recurrence Equations - With Applications to Analysis of Recursive Algorithms
- B.2 Solving Recurrences Using the Characteristic Equation
- B.3 Solving Recurrences by Substitution
- B.4 Extending Results for n, a Power of a Positive Constant b, to n in General
- B.5 Proofs of Theorems
- Exercises
- Appendix C: Data Structures for Disjoint Sets
- References
- Index
- Index_B
- Index_C
- Index_D
- Index_E
- Index_F
- Index_G
- Index_H
- Index_I
- Index_J
- Index_K
- Index_L
- Index_M
- Index_N
- Index_O
- Index_P
- Index_Q
- Index_R
- Index_S
- Index_T
- Index_U
- Index_V
- Index_W-X
- Index_Y
- Index_Z
- List of Figures
- List of Tables
- List of Algorithms, Examples, and Theorems
- List of Sidebars