{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec03_ComplexityBasic_Count_2

# Lec03_ComplexityBasic_Count_2 - Topics Instruction count...

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

Topics Instruction count for statements Methods Examples

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

View Full Document
Deriving Instruction Counts Given a (non-recursive) algorithm expressed in pseudo code we explain how to: Assign counts to high level statements Describe methods for deriving an instruction count Compute counts for several examples
Counts for High Level Statements Assignment loop condition for loop for loop body for loop control while loop while loop control while loop body if Note: The counts we use are not accurate; The goal is to derive a correct growth function

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

View Full Document
Assignment Statement 1. A= B*C-D/F Count 1 = 1 In reality? At least 4 Note: When numbers B, C, D, F are very large, algorithms that deal with large numbers will be used and the count will depend on the number of digits needed to store the large numbers.
Loop condition 1. (i < n)&&(!found) Count 1 = 1 Note : if loop condition invokes functions, count of function must be used

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

View Full Document
for loop body 1. for (i=0; i < n; i++) 2. A[i] = i Count 2 = 1 Count 1(2) = How many times are there for the condition check? i = 0 i < n A[i] = i i = i + 1 true false - = 1 0 2 Count n i
for loop control 1. for (i=0; i < n; i++) 2. <body> Count = number times loop condition is executed (assuming loop condition has a count of 1) i = 0 i < n Body of the loop i = i + 1 true false

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 / 28

Lec03_ComplexityBasic_Count_2 - Topics Instruction count...

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

View Full Document
Ask a homework question - tutors are online