complexity theory - Step Count in Algorithm -


what step count algorithm in terms of n ?

sequentialsearch(a,x,n) {     i=n;     [0]=x;     while(a [i]!= x)         = i-1     return } 

please mention count each step here.thanks!

i hope looking for:

while (a[i] != x) = i-1; 

worst case: scan whole array, a[n] a[0] = o(n)

mean case: scan half array o(n/2) = o(n)

complexity o(n)


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -