Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以说,
我在一个数组中有 1000 个元素,我想在该数组中搜索 10 个元素,那么哪种搜索机制最合适?
另外,如果我需要从同一个数组中搜索 900 个元素,那么哪种搜索方法比较好?
线性搜索还是二分搜索?
提前致谢。
如果元素未排序,则无法进行二进制搜索。但是二进制搜索比线性搜索快得多(您需要查看平均 10 个元素而不是 500 个元素),您最好对列表进行排序(使用诸如快速排序之类的算法)然后进行二进制搜索.