This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: The worst case occurs when b is not in the array, and the loop executes exactly n times, and the final line (Line 7) also gets executed. Alternatively, we could do an average case analysis that assumes something about how likely it is for b to be in the array, and where it is likely to be if it is in the array. We will almost always do a worstcase analysis, but if we knew that b was definitely in the array and was equally likely to be at any location i , we could compute the average number of times the loop executes as: Hence, the average running time is also O ( n )...
View
Full Document
 Spring '10
 fleck
 Algorithms, Array, Analysis of algorithms, Computational complexity theory, running time, average case

Click to edit the document details