# CH01 - CS520 Advanced Analysis of Algorithms and Complexity...

This preview shows pages 1–3. Sign up to view the full content.

TECH Computer Science CS520 Advanced Analysis of Algorithms and Complexity Dr. Ben Choi Ph.D. in EE (Computer Engineering), The Ohio State University System Performance Engineer, Lucent Technologies - Bell Labs Innovations Pilot, FAA certified pilot for airplanes and helicopters 4 BenChoi.info What is a Computer Algorithm? A computer algorithm is 4 a detailed step-by-step method for 4 solving a problem 4 by using a computer. Problem-Solving (Science and Engineering) Analysis 4 How does it work? 4 Breaking a system down to known components 4 How the components relate to each other 4 Breaking a process down to known functions Synthesis 4 Building tools and toys! 4 What components are needed 4 How the components should be put together 4 Composing functions to form a process Problem Solving Using Computers Problem: Strategy: Algorithm: 4 Input: 4 Output: 4 Step: Analysis: 4 Correctness: 4 Time & Space: 4 Optimality: Implementation: Verification: Example: Search in an unordered array Problem: 4 Let E be an array containing n entries, E[0], …, E[n-1], in no particular order. 4 Find an index of a specified key K, if K is in the array; 4 return –1 as the answer if K is not in the array. Strategy: 4 Compare K to each entry in turn until a match is found or the array is exhausted. 4 If K is not in the array, the algorithm returns –1 as its answer. Example: Sequential Search, Unordered Algorithm (and data structure) 4 Input: E, n, K, where E is an array with n entries (indexed 0, …, n-1), and K is the item sought. For simplicity, we assume that K and the entries of E are integers, as is n. 4 Output: Returns ans, the location of K in E (-1 if K is not found.)

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

View Full Document
Algorithm: Step (Specification) int seqSearch(int[] E, int n, int K) 1. int ans, index; 2. ans = -1; // Assume failure. 3. for (index = 0; index < n; index++) 4. if (K == E[index]) 5. ans = index; // Success! 6. break; // Done! 7. return ans; Analysis of the Algorithm How shall we measure the amount of work done by an algorithm? Basic Operation: 4 Comparison of x with an array entry Worst-Case Analysis: 4 Let W(n) be a function. W(n) is the maximum number of basic operations performed by the algorithm on any input size n. 4 For our example, clearly W(n) = n. 4 The worst cases occur when K appears only in the last position in the array and when K is not in the array at all. Average-Behavior Analysis: 4 Let q be the probability that K is in the array 4 A(n) = n(1 – ½ q) + ½ q Optimality: 4 The Best possible solution? 4 Searching an Ordered Array 4 Using Binary Search 4 W(n) = Ceiling[lg(n+1)] 4 The Binary Search algorithm is optimal. Correctness: (Proving Correctness of Procedures s3.5) More Analysis of the Algorithm ()  1 lg + = n What is CS 520?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

CH01 - CS520 Advanced Analysis of Algorithms and Complexity...

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

View Full Document
Ask a homework question - tutors are online