最快的搜索在未排序的数组中的元素的方式 [英] Fastest way to search for an element in unsorted array

查看:182
本文介绍了最快的搜索在未排序的数组中的元素的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是撞到了这个问题今天并试图寻求解决方案,比O(N)更好,但未能拿出之一。

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 this question.

请问有什么解决比为O(n)更好还是不能得到解决比这更好的了问题?

Is there any solution better than O(n) or is it a problem that cannot be solved better than that?

我最初的想法是二进制搜索,但再次,你需要对它进行排序这又是>ñ。我也想过申请快速排序的只是数组的一半到搜索元素可能属于但我们再次用N比较最初并舍弃另一半只是后来的。我会得到这个权利还是我在看一个错误的方向解决?

My initial thought was Binary Search but again for that you need to sort it which is again >n. I also thought of applying quicksort for just the half of the array to which the search element might belong but again we are making n comparisons initially and discarding the other half only later. Am I getting this right or am I looking at the solution in a wrong direction?

我是想在C解决方案++,没有JavaScript的的IndexOf()或C#Array.find()或LINQ的。

I was trying for a solution in c++ and no javascript's IndexOf() or C# Array.find() or LINQ's.

推荐答案

使其平行。鸿沟块阵列和并行搜索。 复杂性将是为O(n),但运行时间将大大减少。实际上它将正比于无。处理器你。

Make it parallel. Divide the array in chunks and search in parallel. The complexity will be O(n) but running time will be much less. Actually it will be proportional to no. of processors you have.

您可以在C使用并行模式库 ++

You can use Parallel Patterns Library in C++

这篇关于最快的搜索在未排序的数组中的元素的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆