The Efficiency of Algorithms

Slides:



Advertisements
Similar presentations
Efficiency of Algorithms Csci 107 Lecture 6-7. Topics –Data cleanup algorithms Copy-over, shuffle-left, converging pointers –Efficiency of data cleanup.
Advertisements

Efficiency of Algorithms
The Efficiency of Algorithms Chapter 3 CS OUR NEXT QUESTION IS: "How do we know we have a good algorithm?" In the lab session, you will explore.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, Java Version, Third Edition.
CPSC 171 Introduction to Computer Science Efficiency of Algorithms.
The Efficiency of Algorithms
CS4413 Divide-and-Conquer
CPSC 171 Introduction to Computer Science More Efficiency of Algorithms.
Efficiency of Algorithms
Chapter 3 The Efficiency of Algorithms
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
CHAPTER 3 CS OUR NEXT QUESTION IS: "How do we know we have a good algorithm?" In the lab session, you will explore algorithms that are related.
CHAPTER 11 Sorting.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Fourth Edition.
Algorithms and Efficiency of Algorithms February 4th.
Chapter 3: The Efficiency of Algorithms
Algorithm Efficiency and Sorting
Efficiency of Algorithms Csci 107 Lecture 6. Last time –Algorithm for pattern matching –Efficiency of algorithms Today –Efficiency of sequential search.
Efficiency of Algorithms February 11th. Efficiency of an algorithm worst case efficiency is the maximum number of steps that an algorithm can take for.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
Chapter 3: The Efficiency of Algorithms
CMPUT101 Introduction to Computing(c) Yngvi Bjornsson & Jia You1 The Efficiency of Algorithms Chapter 3 Topics: Attributes of Algorithms A Choice of Algorithms.
CS107 Introduction to Computer Science Lecture 7, 8 An Introduction to Algorithms: Efficiency of algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Analysis of Algorithms CPS212 Gordon College. Measuring the efficiency of algorithms There are 2 algorithms: algo1 and algo2 that produce the same results.
BIT Presentation 4.  An algorithm is a method for solving a class of problems.  While computer scientists think a lot about algorithms, the term.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
1 Chapter 3: Efficiency of Algorithms Quality attributes for algorithms Correctness: It should do things right No flaws in design of the algorithm Maintainability.
计算机科学概述 Introduction to Computer Science 陆嘉恒 中国人民大学 信息学院
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 9: Algorithm Efficiency and Sorting Data Abstraction &
CS261 – Recitation 5 Fall Outline Assignment 3: Memory and Timing Tests Binary Search Algorithm Binary Search Tree Add/Remove examples 1.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
“Enthusiasm releases the drive to carry you over obstacles and adds significance to all you do.” – Norman Vincent Peale Thought for the Day.
© 2006 Pearson Addison-Wesley. All rights reserved10 B-1 Chapter 10 (continued) Algorithm Efficiency and Sorting.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Invitation to Computer Science 6th Edition Chapter 3 The Efficiency of Algorithms.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
MA/CSSE 473 Day 30 Optimal BSTs. MA/CSSE 473 Day 30 Student Questions Optimal Linked Lists Expected Lookup time in a Binary Tree Optimal Binary Tree (intro)
MA/CSSE 473 Days Optimal linked lists Optimal BSTs.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 13 Artificial Intelligence. Artificial Intelligence – Figure 13.1 The Turing Test.
CS 302 Data Structures Algorithm Efficiency.
An Iterative FFT We rewrite the loop to calculate nkyk[1] once
Algorithm Efficiency and Sorting
The Efficiency of Algorithms
Algorithm Efficiency and Sorting
Chapter 3: The Efficiency of Algorithms
MSIS 655 Advanced Business Applications Programming
Algorithm Efficiency and Sorting
Chapter 3: The Efficiency of Algorithms
3. Brute Force Selection sort Brute-Force string matching
Searching and Sorting Arrays
Algorithm Efficiency and Sorting
3. Brute Force Selection sort Brute-Force string matching
Data Structures & Algorithms
Algorithm Efficiency and Sorting
Algorithm Efficiency and Sorting
Algorithm Efficiency and Sorting
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Applications of Arrays
Invitation to Computer Science 5th Edition
3. Brute Force Selection sort Brute-Force string matching
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 3.3.1 The Shuffle-Left Algorithm- The Value of Legit – After Last Item is Copied, the Result is This

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

Figure 3.3.1 – 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 3.3.1 The Shuffle-Left Algorithm – The Value of Legit - The 36, 42, 23, and 21 Are Passed Over; This is the Result

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

Figure 3.3.1 – 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 3.3.3 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 3.3.3 The Converging-Pointers Algorithm – The Value of Legit – Position Right is Copied Into Position Left

Figure 3.3.3 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 3.25 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

Exercises – A Linked List

Exercises Draw a Linked List when Data Cleanup is Performed on This Linked List