CS300-01_Algorithm_Analysis

# CS300-01_Algorithm_Analysis - Algorithm Analysis Sung Yong...

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

1 Algorithm Analysis Sung Yong Shin CS Dept. KAIST

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

View Full Document
2 Outline 1. Introduction 2. Analyzing Algorithms and Problems 3. Asymptotic Growth Rate
3 1. Introduction Definition : ( Algorithm ) An algorithm is a finite sequence of instructions, if followed, to accomplish a particular task Five characteristics of an algorithm Input : Zero or more quantities (data) are supplied externally Output : At least one quantity (data) is produced Definiteness : Each instruction must be clear and unambiguous Finiteness : An algorithm is required to terminate after a finite number of steps Effectiveness : Every instruction must be sufficiently basic so that anyone can follow Input Output

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

View Full Document
The characterization of a solution of a problem S is a solution of problem A if and only if S satisfies property C C is said to be the characterization of a solution. 4 Good algorithm Good characterization Why ? (What dose it mean by “good” ?) Is its converse true ? Well, . ..... Seemingly not but nobody knows !!! S is a solution S satisfies C ) ( NP P
5 Algorithm description languages pidgin ALGOL FORGOL Java Unambiguous Independent of computers Easy to translate into a computer language

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

View Full Document
6 2. Analyzing Algorithms and Problems Correctness Efficiency Amount of work done (time complexities) Amount of space used (space complexities) Optimality Simplicity (clarity)
7 Correctness Precise problem statement: What inputs to work on What results to produce Solution method Implementation A sequence of instructions for carrying it out Input Output

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

View Full Document
8 How to Prove Correctness Loop invariants Program structure Definition: (Loop invariant) Loop invariants are conditions and relationships that are satisfied by the variables and data structures at the end(beginning) of each iteration of the loop. Establish loop invariants by mathematical induction !! Loop
9 Example Given an array L containing n elements ( n 0 ) and a number x , find the index of the first occurrence of x in L , if x is in L , and report 0 otherwise. What is input? L and x What is output ? If x L , the index of the first occurrence of x Otherwise, 0 Algorithm 1. index := 1 ; 2. while index n and L(index) x do 3. index := index + 1 4. end {while} 5. if index n , then index := 0 end; Sequential search !!!

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

View Full Document
[Proof] By induction Obvious Suppose that index = k and L ( i ) x for 1 i < k when line 2 is executed k times for some 1 k < n
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 28

CS300-01_Algorithm_Analysis - Algorithm Analysis Sung Yong...

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

View Full Document
Ask a homework question - tutors are online