What is Median of Sorted Arrays in O(log n) complexity ?
+1
A:
Do anything you want for O(log n)
, then finish by returning the value in O(1)
?
return array[array.length / 2];
Edit: this is not fully complete:
- It's not proper language syntax (since it's an algorithm problem)
- It doesn't address an even number of array elements
280Z28
2009-08-29 03:46:59
+2
A:
if array length is odd
take element # (length+1)/2
else
take average of element # length/2 and # length/2 - 1
Ben Alpert
2009-08-29 03:55:08
The fact that this answer was chosen as the accepted answer is a testament to the question's rediculousness. The OP is just a question pump.
Ether
2010-01-09 20:02:19