algorithm - Average Case Time Complexity Analysis of Binary Counter Increment -


i attempting find average case time complexity, not amortized analysis, of binary counter. not entirely confident in time complexity analyzing skills, confirm average case analysis of pseudocode provided below correct.

let k length of array.

increment(array)     = 0     while < k , array[i] == 1         array[i] = o         = + 1     if < k         array[i] = 1 

in order find average time taken, find average amount of bits flipped per run. result, found o(2+k/(2^k)), equals o(1) large k.

is correct average case running time? if not, how begin approach problem?

i assuming each input has same probability occur

this means each bit independently on or off probability 1/2.

the geometric distribution relevant distribution complexity: flip coins, , end experiment on first tail outcome (there nothing further carry).

the mean of geometric distribution here 2 (see above link, or derive basic principles), average complexity indeed o(1).


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -