15.5 Running Time Analysis of Searching and Sorting Algorithms
In studying the running time of various searching and sorting algorithms, we will look at the following scenarios:
best case
worst case
average case
Some methods have a very efficient running time. We mentioned earlier that the running time of Binary Search was log n. Thus, searching a sorted array of 1 billion items using Binary Search will take only 30 statement executions since log (1 billion) is approximately 30.
Example 15.7 shows the code for a recursive binary search.
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.