L10_TimeComplexity

# L10_TimeComplexity - The Big-O Notation The big-O notation...

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

The Big-O Notation The big-O notation gives a qualitative insight as to how changes in problem size affects the performance of an algorithm when the problem size is large. Notation O ( N 2 ) is read as big-oh of N squared . Page 1 of 29

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

View Full Document
Rule 1 of simplification when using big-O notation: Remove all terms whose contribution to the total ceases to be significant as the problem size becomes large. Examples 1 n + is ) . ( On 2 n is ) . 2 ( 2 1 nn ++ is . () 832 2 nnnn +−+− is . 8 Page 2 of 29
NOW LET’S CONTINUE Page 3 of 29

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

View Full Document
Consider the following algorithm: void Counting(double[] array, Counter c1) { c1.npos = 0; c1.nneg = 0; for (int i=0; i<array.length; i++) if (array[i] > 0) c1.npos += 1; e l s e c 1 . n n e g += 1 ; } The complexity of Counting is O (___). Page 4 of 29
Consider the following algorithm: void Counting(double[] array, Counter c1) { c1.npos = 0; c1.nneg = 0; for (int i=0; i<array.length; i++) if (array[i]>0) c1.npos += 1; for (int i=0; i<array.length; i++) if (array[i]<=0) c1.nneg += 1; } The complexity of Counting2 is O (___). Page 5 of 29

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

View Full Document
The Big-O Notation The function 2 n is said to be O ( n ) because the coefficient 2 does not affect the growth pattern. Page 6 of 29
Growth Patterns O (2 n ) O ( n ) Problem size Time taken Problem size Time taken p T' p t 2 p 2 T’ 2 p 2 t 3 p 3 T’ 3 p 3 t 50 p 50 T’ 50 p 50 t Page 7 of 29

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

L10_TimeComplexity - The Big-O Notation The big-O notation...

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

View Full Document
Ask a homework question - tutors are online