solu3 - This le contains the exercises, hints, and...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
This fle contains the exercises, hints, and solutions For Chapter 3 oF the book ”Introduction to the Design and Analysis oF Algorithms,” 2nd edition, by 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 a n 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 a n mod m where a> 1 and n is a large positive integer, how would you circumvent the problem oF a very large magnitude oF a n ? 3. ±or 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 )= a n x n + a n 1 x n 1 + ... + a 1 x + a 0 at a given point x 0 and determine its worst-case efficiency class. b. IF the algorithm you designed is in Θ( n 2 ) , 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 defnition oF a stable sorting algorithm was g iveninSect ion1 .3 .) 7. Is it possible to implement selection sort For linked lists with the same Θ( n 2 ) efficiency as the array version? 8. Sort the list 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
b. Write a pseudocode of the method that incorporates this improve- ment. c. Prove that the worst-case efficiency of the improved version is quadratic. 10. Is bubble sort stable? 11. Alternating disks You have a row of 2 n disks of two colors, n dark and n light. They alternate: dark, light, dark, light, and so on. You want to get all the dark disks to the right-hand end, and all the light disks to the left-hand end. The only moves you are allowed to make are those which interchange the positions of two neighboring disks. Design an algorithm for solving this puzzle and determine the number of moves it makes. [Gar99], p.75 2
Background image of page 2
Hints to Exercises 3.1 1. a. Think of algorithms that have impressed you with their efficiency and/or sophistication. Neither characteristic is indicative of a brute- force algorithm. b. Surprisingly, it is not a very easy question to answer. Mathemati- cal problems (including those you have studied in your secondary school and college courses) are a good source of such examples.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 28

solu3 - This le contains the exercises, hints, and...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online