DS01_Ch02a - CHAPTER 2 ALGORITHM ANALYSIS Definition An...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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 Right Arrow Icon
Ask a homework question - tutors are online