A. Levitin. The problems that might be challenging for at least some students are marked by ; those that might be difficult for a majority of students are marked by .
Exercises 3.1
1. a. Give an example of an algorithm that should not be considered an application of the brute-force approach.
b. Give an example of a problem that cannot be solved by a brute-force algorithm. 2. a. What is the efficiency of the brute-force algorithm for computing an as a function of n? As a function of the number of bits in the binary representation of n?
b. If you are to compute an mod m where a > 1 and n is a large positive integer, how would you circumvent the problem of a very large magnitude of an ?
3. For each of the algorithms in Problems 4, 5, and 6 of Exercises 2.3, tell whether or not the algorithm is based on the brute-force approach.
4. a. Design a brute-force algorithm for computing the value of a polynomial p(x) = an xn + an−1 xn−1 + ... + a1 x + a0 at a given point x0 and determine its worst-case efficiency class.
b. If the algorithm you designed is in Θ(n2 ), design a linear algorithm for this problem.
c. Is it possible to design an algorithm with a better than linear efficiency for this problem?
5. Sort the list E, X, A, M, P, L, E in alphabetical order by selection sort.
6. Is selection sort stable? (The definition of a stable sorting algorithm was given in Section 1.3.)
7. Is it possible to implement selection sort for linked lists with the same
Θ(n2 ) efficiency as the array version?
8. Sort the list E, X, A, M, P, L, E in alphabetical order by bubble sort.
9. a. Prove that if bubble sort makes no exchanges on its pass through a list, the list is sorted and the algorithm can be stopped.
1
b. Write a pseudocode of the method that incorporates this improvement.
c. Prove that the worst-case efficiency of the improved version is