 The Efficiency of Algorithms

Presentation on theme: "The Efficiency of Algorithms"— Presentation transcript:

The Efficiency of Algorithms
Chapter 3 The Efficiency of Algorithms

Figure 3.3 A Choice of Algorithms

Figure 3.3.1 The Shuffle-Left Algorithm – Original Configuration

Figure 3.3.1 The Shuffle-Left Algorithm – The Value of Legit- First Copy

Figure 3.3.1 The Shuffle-Left Algorithm – The Value of Legit – Second Copy

Figure 3.3.1 The Shuffle-Left Algorithm – The Value of Legit – The Third Copy

Figure The Shuffle-Left Algorithm- The Value of Legit – After Last Item is Copied, the Result is This

Figure The Shuffle-Left Algorithm – The Value of Legit – Reset the Right Hand Finger to Start Again

Figure – The Shuffle-Left Algorithm – The Value of Legit – Left and Right Hand Finger Move Forward

Figure 3.3.1 – The Shuffle Left Algorithm – The Value of Legit – Moving along, we pass over the 16.

Figure 3.3.1 The Shuffle-Left Algorithm – The Value of Legit-Seven Copies squeeze out O

Figure The Shuffle-Left Algorithm – The Value of Legit - The 36, 42, 23, and 21 Are Passed Over; This is the Result

Figure The Shuffle-Left Algorithm – The Value of Legit – Squeezing out Final 0 Gives This Result

Figure – The Shuffle Left Algorithm – The Value of Legit – The Left Hand Finger is Pointing At a Nonzero Element, so Another Advance of Both Fingers Gives Us This Configuration.

Figure 3.3.2 The Copy-Over Algorithm

Figure 3.3.3 The Converging-Pointers Algorithm – The Value of Legit

Figure The Converging-Pointers Algorithm – The Value of Legit – Legit and Right Are Reduced by 1.

Figure 3.3.3 The Converging-Pointers Algorithm – The Value of Legit – The Value of Left Increases

Figure The Converging-Pointers Algorithm – The Value of Legit – Position Right is Copied Into Position Left

Figure The Converging-Pointers Algorithm – The Value of Legit –Item at Position Left is Still 0, Another Copy Takes Place

Practice Problems - In the Data Cleanup Problem, Suppose the Original Data Is Like This

Figure 3.6 Values of Magnitude – Work = 2n

Figure 3.7 Order of Magnitude - Work = cn for Various Values of c

Figure 3.8 – Order of Magnitude – Growth of Work = cn for Various Values of c

Figure 3.9 Order of Magnitude -Table of Calling Information

Figure 3.10 –Order of Magnitude – Work = cn2 for Various Values c

Figure 3.11 The 0rder of Magnitude – A Comparison of n and n2

Figure 3. 12 – Order of Magnitude – For Large Enough n, 0
Figure 3.12 – Order of Magnitude – For Large Enough n, 0.25n2 Has Larger Values than 10n

Figure 3.13 Order of Magnitude – A Comparison of Two Extreme Θ (n2) and Θ (n) Algorithms

Using the Information in Figure 3
Using the Information in Figure 3.5 Fill in the Above Table for the Number of Comparisons required in the Sequential Search Algorithm

Figure 3.14 Analysis of Algorithms – Analysis of Three Data Cleanup Algorithms

Figure 3.16 Selection Sort Algorithms – Comparisons Required by Selection Sort

Figure 3.17 –Selection Sort Algorithms - An Attempt to Exchange the Values at X and Y

Figure 3.18 Selection Sort Algorithms – Exchanging the Values of X and Y

Figure 3.21 Binary Search – Values of n and lg n

Figure 3.22 Binary Search – A comparison of n and lg n

Figure 3.23 Summary – Order-of-Magnitude Time Efficiency Summary

Figure 3.24 When Things Get Out of Hand – Four Connected Cities

Figure When Things Get Out of Hand – Hamiltonian Circuits Among All Paths from A in Figure 3.24 with Four Links

Figure 3.26 (a) When Things Get Out of Hand – Comparisons of lg n, n, n2, and 2n

Figure 3.26 (b) When Things Get Out of Hand – Comparisons of lg n,n, n2, and 2n

Figure 3.28 Approximation Problems – A First-Fit Solution to a Bin-Packing Problem

Practice Problems – Tree Shows All Paths with Two Links That Begin At Node A

Exercises – Write the Data List that Results from running the Shuffle-Left Algorithm to clean up this Data