Marcelo de Sousa
Marcelo de Sousa

Reputation: 195

binary search on a single linked list

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

Answers (1)

user4842163
user4842163

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

Related Questions