This preview shows pages 1–2. Sign up to view the full content.
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
This note was uploaded on 12/24/2010 for the course CS CS 173 taught by Professor Fleck during the Spring '10 term at University of Illinois, Urbana Champaign.
 Spring '10
 fleck
 Algorithms

Click to edit the document details