Analysis 1.3 - – Does not qualitatively alter the growth...

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

View Full Document Right Arrow Icon
Last Updated: 10/01/12 5:45 AM CSE 2011 Prof. J. Elder - 11 - Counting Primitive Operations By inspecting the pseudocode, we can determine the maximum number of primitive operations executed by an algorithm, as a function of the input size Algorithm arrayMax ( A , n ) # operations currentMax A [0] 2 for i 1 to n - 1 do 2 n if A [ i ] > currentMax then 2( n -1) currentMax A [ i ] 2( n -1) return currentMax 1 Total 6 n -1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last Updated: 10/01/12 5:45 AM CSE 2011 Prof. J. Elder - 12 - Estimating Running Time • Algorithm arrayMax executes 6 n ± 1 primitive operations in the worst case. Define: a = Time taken by the fastest primitive operation b = Time taken by the slowest primitive operation • Let T ( n ) be worst-case time of arrayMax. Then a (6 n ± 1) T ( n ) b (6 n ± 1) • Hence, the running time T ( n ) is bounded by two linear functions
Background image of page 2
Last Updated: 10/01/12 5:45 AM CSE 2011 Prof. J. Elder - 13 - Growth Rate of Running Time Changing the hardware/ software environment – Affects T ( n ) by a constant factor, but
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: – Does not qualitatively alter the growth rate of T ( n ) • The linear growth rate of the running time T ( n ) is an intrinsic property of algorithm arrayMax Last Updated: 10/01/12 5:45 AM CSE 2011 Prof. J. Elder - 14 - Constant Factors • On a logarithmic scale, the growth rate is not affected by – constant factors or – lower-order terms • Examples – 10 2 n + 10 5 is a linear function – 10 5 n 2 + 10 8 n is a quadratic function Last Updated: 10/01/12 5:45 AM CSE 2011 Prof. J. Elder - 15 - Seven Important Functions • Seven functions that often appear in algorithm analysis: – Constant ≈ 1 – Logarithmic ≈ log n – Linear ≈ n – N-Log-N ≈ n log n – Quadratic ≈ n 2 – Cubic ≈ n 3 – Exponential ≈ 2 n • In a log-log chart, the slope of the line corresponds to the growth rate of the function. We will follow the convention that log n ! log 2 n ....
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

Analysis 1.3 - – Does not qualitatively alter the growth...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online