Computer Science 101 A Survey of Computer Science Timing Problems.

Slides:



Advertisements
Similar presentations
Chapter 3 Brute Force Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions.
Advertisements

Introduction to Computer Science Theory
Computer Science 101 Efficiency and Complexity Analysis.
Sorting CMSC 201. Sorting In computer science, there is often more than one way to do something. Sorting is a good example of this!
CS4413 Divide-and-Conquer
Foundations of Algorithms, Fourth Edition
Advanced Topics in Algorithms and Data Structures Lecture pg 1 Recursion.
CSC 2300 Data Structures & Algorithms March 23, 2007 Chapter 7. Sorting.
CPSC 171 Introduction to Computer Science More Efficiency of Algorithms.
CS 171: Introduction to Computer Science II Quicksort.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Chapter 11 Sorting and Searching. Topics Searching –Linear –Binary Sorting –Selection Sort –Bubble Sort.
Efficiency of Algorithms
Wednesday, 11/25/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/25/02  QUESTIONS??  Today:  More on sorting. Advanced sorting algorithms.  Complexity:
CS107 Introduction to Computer Science
CS2420: Lecture 10 Vladimir Kulyukin Computer Science Department Utah State University.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (1) Asymptotic Complexity 10/28/2008 Yang Song.
Chapter 3: The Efficiency of Algorithms
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
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.
Chapter 16: Searching, Sorting, and the vector Type.
Computer Science: A Structured Programming Approach Using C1 8-5 Sorting One of the most common applications in computer science is sorting—the process.
{ 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)
Quick Sort By: HMA. RECAP: Divide and Conquer Algorithms This term refers to recursive problem-solving strategies in which 2 cases are identified: A case.
计算机科学概述 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.
Analysis of Algorithms
Chapter 19: Searching and Sorting Algorithms
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
1 Searching and Sorting Linear Search Binary Search.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
1 Sorting Algorithms Sections 7.1 to Comparison-Based Sorting Input – 2,3,1,15,11,23,1 Output – 1,1,2,3,11,15,23 Class ‘Animals’ – Sort Objects.
Summary Algorithms Flow charts Bubble sort Quick sort Binary search Bin Packing.
Chapter 12 Binary Search and QuickSort Fundamentals of Java.
Order of an algorithm The order of an algorithm tells you how efficient it is. The more efficient the quicker it is to complete it. This is important in.
Lecture 7. Solution by Substitution Method T(n) = 2 T(n/2) + n Substitute n/2 into the main equation 2T(n/2) = 2(2(T(n/4)) + n/2) = 4T(n/4) + n And T(n)
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Computer Science 101 Fast Algorithms. What Is Really Fast? n O(log 2 n) O(n) O(n 2 )O(2 n )
CS 615: Design & Analysis of Algorithms Chapter 2: Efficiency of Algorithms.
Decision Problems Optimization problems : minimum, maximum, smallest, largest Satisfaction (SAT) problems : Traveling salesman, Clique, Vertex-Cover,
Complexity Analysis. 2 Complexity The complexity of an algorithm quantifies the resources needed as a function of the amount of input data size. The resource.
Lecture 6 Analysis of Iterative Algorithms Sorting Algorithms.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Searching Topics Sequential Search Binary Search.
Comp 245 Data Structures Analysis of Algorithms. Purpose A professional programmer must be able to determine how efficient his code is. Efficiency, as.
1 The Role of Algorithms in Computing. 2 Computational problems A computational problem specifies an input-output relationship  What does the.
Chapter 16: Searching, Sorting, and the vector Type.
Chapter 16: Searching, Sorting, and the vector Type
Searching and Sorting Algorithms
CMSC201 Computer Science I for Majors Lecture 23 – Sorting
Computer Science 101 A Survey of Computer Science
Topics discussed in this section:
Sorting Data are arranged according to their values.
Topics discussed in this section:
Intro to Recursion.
Chapter 3: The Efficiency of Algorithms
Sorting Data are arranged according to their values.
Sorting.
Algorithm Efficiency and Sorting
Algorithmic Complexity
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Algorithm Efficiency and Sorting
Time Complexity Lecture 15 Mon, Feb 27, 2006.
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Presentation transcript:

Computer Science 101 A Survey of Computer Science Timing Problems

Efficiency Classes - Timing Problems We can use our knowledge of the efficiency class of an algorithm to make predictions about the execution time for a large data set based on the time observed for a smaller set using the same machine and program.

Timing Example - Sequential Search Suppose we have done several trials of Sequential Search on a set of 1000 elements and the average time is about.5 sec. Suppose we have done several trials of Sequential Search on a set of 1000 elements and the average time is about.5 sec. How long would we expect for 10,000 element searches using the same machine and same program? How long would we expect for 10,000 element searches using the same machine and same program?

Timing Example - Sequential Search Given: T(1000) .5 sec. Given: T(1000) .5 sec. Wanted: T(10,000) Wanted: T(10,000) Recall that for Sequential Search, T(n)  Kn. Recall that for Sequential Search, T(n)  Kn. If we knew the value of K, we could just “plug in” the value 10,000 for n to get the time. If we knew the value of K, we could just “plug in” the value 10,000 for n to get the time.

Timing Problem Structure These timing problems have the general form: These timing problems have the general form: –A specific algorithm is specified –We’re given approximate time for some specific size problem –We know the efficiency formula for the algorithm –We’re asked to approximate the time for this algorithm on some specified larger size problem

Timing Problem Strategy The timing problems we’ll work with have a single constant, say K The timing problems we’ll work with have a single constant, say K We’ll use the information given for the smaller size problem to solve for an approximate value of K We’ll use the information given for the smaller size problem to solve for an approximate value of K This gives us a formula for the approximate time of this algorithm on given machine, etc. without K This gives us a formula for the approximate time of this algorithm on given machine, etc. without K We can then “plug in” the larger size to compute approximate time for larger problem. We can then “plug in” the larger size to compute approximate time for larger problem.

Back to Sequential Search Example So we have T(n)  Kn, and we are given that T(1000) .5 sec So we have T(n)  Kn, and we are given that T(1000) .5 sec So, T(1000)  K .5, gives K .5/1000 = 1/2000. This gives T(n)  (1/2000)n (without K) So, T(1000)  K .5, gives K .5/1000 = 1/2000. This gives T(n)  (1/2000)n (without K) So T(10000)  (1/2000) = 5 sec. So T(10000)  (1/2000) = 5 sec.

Timing Example - Sequential Search How long would we expect for 1,000,000 element searches? How long would we expect for 1,000,000 element searches? We have T(n)  (1/2000)n So T(1,000,000)  (1/2000) = 500 sec.  8.33 min. We have T(n)  (1/2000)n So T(1,000,000)  (1/2000) = 500 sec.  8.33 min.

Timing Example - Bubble Sort Suppose Bubble Sort on 1000 elements takes.5 sec. Suppose Bubble Sort on 1000 elements takes.5 sec. How long to sort 10,000 elements with Bubble Sort? How long to sort 10,000 elements with Bubble Sort? For Bubble Sort, T(n)  Kn 2. Using T(1000)  K .5, gives K .5/ and T(n)  (.5/ ) n 2 For Bubble Sort, T(n)  Kn 2. Using T(1000)  K .5, gives K .5/ and T(n)  (.5/ ) n 2 So T(10000)  (.5/ ) = = 50 sec. So T(10000)  (.5/ ) = = 50 sec.

Timing Example - Bubble Sort How long to sort 1,000,000 elements with Bubble Sort? How long to sort 1,000,000 elements with Bubble Sort? We have T(n)  (.5/ ). n 2 So T(1,000,000)  (.5/ ) = = sec. > 5.7 days. We have T(n)  (.5/ ). n 2 So T(1,000,000)  (.5/ ) = = sec. > 5.7 days.

Timing Example - Quicksort Suppose for Quicksort, T(1000) .5 sec. Suppose for Quicksort, T(1000) .5 sec. Estimate T(10,000). Estimate T(10,000). For Quicksort, T(n)  Kn Lg(n) For Quicksort, T(n)  Kn Lg(n) Using T(1000)  K .5, gives K  1/20,000 and T(n)  (1/20000) n Lg(n) Using T(1000)  K .5, gives K  1/20,000 and T(n)  (1/20000) n Lg(n) So T(10000)  (1/20000)  6.5 sec. So T(10000)  (1/20000)  6.5 sec.

Timing Example - Quicksort Estimate T(1,000,000). Estimate T(1,000,000). We have T(n)  (1/20,000)n Lg(n) We have T(n)  (1/20,000)n Lg(n) So T(1,000,000)  (1/20000)  1000 sec. < 17 min. So T(1,000,000)  (1/20000)  1000 sec. < 17 min.

Timing Example - Binary Search Suppose for Binary Search, T(1000) .5 sec. Suppose for Binary Search, T(1000) .5 sec. Estimate T(10,000). Estimate T(10,000). For Binary Search, T(n)  K Lg(n) For Binary Search, T(n)  K Lg(n) Using T(1000)  K. 10 .5, gives K  1/20 and T(n)  (1/20) Lg(n) Using T(1000)  K. 10 .5, gives K  1/20 and T(n)  (1/20) Lg(n) So T(10000)  (1/20). 13 .65 sec. So T(10000)  (1/20). 13 .65 sec.

Timing Example - Binary Search Estimate T(1,000,000). Estimate T(1,000,000). We have T(n)  (1/20)Lg(n) We have T(n)  (1/20)Lg(n) So T( )  (1/20). 20  1 sec. So T( )  (1/20). 20  1 sec.

Timing Examples - Summary Suppose for algorithm A, T(1000) .5 sec. Algorithm T(10,000) T(1, ) Sequential Search5 sec min. Search for Largest5 sec min. Selection Sort 50 sec. 5.7 days Bubble Sort 50 sec. 5.7 days Quicksort 6.5 sec. 17 min. Binary Search.65 sec. 1 sec.