Professional Documents
Culture Documents
continues…
Asymptotic analysis
• Time Complexity (T(n)) - count of “elementary steps“ / “instructions” executed
• There is a problem!! Exact count of elementary steps (T(n)) depends on distribution of
input
• Consider Linear Search algorithm for input size n = 100000; check the table-
‘key’ found in position T(n) The comparison “if(A[i] == key)” inside for - loop will run
• n times in worst possible situation – linear in terms of input
Nowhere =n
size n
100000 =n • Element found in the last position
99999 =n-1 • Element NOT found
• Constant number of times in best possible situation
⁞ ⁞
• Element found in first position
1 =1 • n/2 times on an average – linear in terms of input size n
n
n-1
= n-2
⁞
n-(n-1)