Fastest way to search for an element in unsorted array

后端 未结 10 1799
北恋
北恋 2020-12-14 08:13

I just bumped on to this question today and was trying for a solution that is better than O(N) but could not come up with one.

Searched through SO but couldn\'t find

10条回答
  •  猫巷女王i
    2020-12-14 09:02

    Yet,there is another logic...

    (Even numbers are stored in even address)

    • First check whether the search element is odd or even

    • If the search element is"even",then perform search only for even adress(Create loop increment to skip odd address)

    • Half the element can be skipped from searching by this logic

    For example:

    • If there are 100 element stored in unordered way and search element is 98.... since the search number is even...u can skip all odd address(so 50 elements are skipped) Now the search is done only for rest 50 even address....

    You can divide the element and search in parallel or Use "pivot key" to sort to rest 50 elements or any other search method

提交回复
热议问题