Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the minimum in an unsorted array in logarithmic time

Is there an algorithmic approach to find the minimum of an unsorted array in logarithmic time ( O(logn) )? Or is it only possible in linear time? I don't want to go parallel.

Thanks

Michael

like image 930
Michael Eilers Smith Avatar asked Dec 02 '22 03:12

Michael Eilers Smith


2 Answers

If the list is unsorted, your search has to be at least linear. You must look at each item at least once, because anything you haven't looked at might be less than what you've already seen.

like image 104
Collin Avatar answered Dec 04 '22 06:12

Collin


Going parallel wouldn't help in general. If you have more processors than n, and you don't count the time it takes to load the data, which is O(n), then yes, you can do it in logarithmic time. But suppose you have, say, 10 numbers per processor. It takes a certain amount of time. Now make it 20 numbers per processor. Each processor will take twice as long to crunch its numbers, before they compare each other's results in parallel. O(n) + O(log n) = O(n).

like image 39
Tom Zych Avatar answered Dec 04 '22 08:12

Tom Zych