# DS01_Ch02a - CHAPTER 2 ALGORITHM ANALYSIS Definition An...

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

CHAPTER 2 ALGORITHM ANALYSIS Definition 【 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition, all algorithms must satisfy the following criteria: (1) Input There are zero or more quantities that are externally supplied . (2) Output At least one quantity is produced . (3) Definiteness Each instruction is clear and unambiguous . (4) Finiteness If we trace out the instructions of an algorithm, then for all cases, the algorithm terminates after finite number of steps . (5) Effectiveness Every instruction must be basic enough to be carried out , in principle, by a person using only pencil and paper. It is not enough that each operation be definite as in(3); it also must be feasible . 1/15

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

View Full Document
Note: A program is written in some programming language, and does not have to be finite ( e.g. an operation system ). An algorithm can be described by human languages, flow charts, some programming languages, or pseudo- code. 【 Example 【 Selection Sort : Sort a set of n 1 integers in increasing order. From those integers that are currently unsorted, find the smallest and place it next in the sorted list. Where and how are they stored? Where? for ( i = 0; i < n; i++) { E xamine list[i] to list[n - 1] and suppose that the smallest integer is at list[min]; I nterchange list[i] and list[min]; } Sort = Find the smallest integer + Interchange it with list[i]. Algorithm in pseudo-code 2/15
What to Analyze Machine & compiler-dependent run times . : machine & compiler- in dependent. Assumptions: instructions are executed sequentially each instruction is simple , and takes exactly one time unit integer size is fixed and we have infinite memory Typically the following two functions are analyzed: T avg ( N ) & T worst ( N ) -- the average and worst case time complexities, respectively, as functions of input size N . If there is more than one input, these functions

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

DS01_Ch02a - CHAPTER 2 ALGORITHM ANALYSIS Definition An...

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

View Full Document
Ask a homework question - tutors are online