binary search on a single linked list

泄露秘密 提交于 2021-01-28 20:29:10

问题


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 .


回答1:


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.



来源:https://stackoverflow.com/questions/33929614/binary-search-on-a-single-linked-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!