Is it O(n log n) or O(log n)?
views:
52answers:
2
A:
Binary search requires random access, hence it's not possible on a linked list. You're stuck with an O(n) linear search.
Steven Sudit
2010-08-18 15:52:28
+2
A:
I'm going to say it's not O(log n) because binary searches don't work well on linked lists - you don't have efficient random access.
If you really tried to do binary search, it would take O(log n) steps, but in each step, you need an O(n) traversal to access the desired element. So you could say it's O(nlog(n)).
You should just do a O(n) linear search instead.
muddybruin
2010-08-18 15:53:17
You don't have *any* random access; all access is linear. But, yes, I agree with your answer.
Steven Sudit
2010-08-18 15:54:11