Reputation: 195
How do I perform a binary search on a single linked list headed ? Also it can do it , if there is any particular method. The EP can not tell in advance how many elements of that list , I have to search and enter a cell between q > prox and p .
Upvotes: 1
Views: 96
Reputation:
Typically this is not possible, since binary search requires random access, and a singly-linked list can only provide forward sequential access. Without being able to jump around in memory and look at some nth
element (either through direct random-access or a skip list), we end up being required to linearly search through the list from beginning to end even if it's sorted.
Upvotes: 1