搜索算法使用 [英] Search algorithm to use

查看:78
本文介绍了搜索算法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个数据库,我知道要按照增加的顺序排序

,并且数组少于50个元素,我想找到

第一个元素大于某个值,是一个简单的线性搜索

这里最好的(从数组开始到结束的循环)?看起来好像

其他一些搜索算法,比如二进制或者这个数据集上没有任何好处。

If I have an array of data that I know to be sorted in increasing
order, and the array is less than 50 elements, and I want to find the
first element greater than a certain value, is a simple linear search
the best here(for loop from beginning to end of array)? It seems like
some other search algorithm like binary or whatever would be of no
benefit on this data set.

推荐答案

joshc写道:
joshc wrote:
如果我有一个数据数组,我知道要按照增加的顺序排序,并且数组少于50个元素,我想找到大于某个值的第一个元素,是一个简单的线性搜索这里最好的(从数组开始到结束的循环)?看起来像其他一些搜索算法,比如二进制或者其他什么对这个数据集没什么好处。
If I have an array of data that I know to be sorted in increasing
order, and the array is less than 50 elements, and I want to find the
first element greater than a certain value, is a simple linear search
the best here(for loop from beginning to end of array)? It seems like
some other search algorithm like binary or whatever would be of no
benefit on this data set.




替代品

- 哈希表 - 插入n个部分O(n);搜索O(1)

- 快速排序 - 排序n个元素O(n log n);搜索O(log n)


哈希表接近最优。


gtoomey



Alternatives
- hash table - insert n slements O(n); search O(1)
- quick sort - sort n elements O(n log n); search O(log n)

A hash table is close to optimal.

gtoomey

joshc写道:
如果我有一个数据数组,我知道要按照增加的顺序排序,并且数组少于50个元素,我想找到
第一个元素大于某个值,是一个简单的线性搜索这里最好的(从数组开始到结束的循环)?看起来像其他一些搜索算法,比如二进制或其他什么对这个数据集没什么好处。
If I have an array of data that I know to be sorted in increasing
order, and the array is less than 50 elements, and I want to find the
first element greater than a certain value, is a simple linear search
the best here(for loop from beginning to end of array)? It seems like
some other search algorithm like binary or whatever would be of no
benefit on this data set.




效率的问题真的是超出界限

的C语言本身;有很多实现

的C和给定操作的时序特征

从一个实现到下一个实现不同。


尽管如此,对于这样一个小阵列来说,似乎很可能(当然不是某种情况)确定线性

搜索和二分搜索之间的差异可以忽略不计。当然,

的方式是实现搜索和b
方法和衡量。当然,即便如此,结果只会对手头的实施有效,而且不会为其他人持有



-

Eric Sosman
es ***** @ acm -dot-org.inva 盖子


我意识到这一点,但不管怎样,还有算法在

一般比别人好。也许你可以为这类问题建议更一般的

编程新闻组?我记得前一段时间来过一段时间,但我很难找到它。一般来说这是一个

编程组。

Eric Sosman写道:
I realize this, but still, regardless, there are algorithms that are in
general better than others. Perhaps you could suggest a more general
programming newsgroup for this type of question? I remember coming
across one some time ago but am having trouble finding it. It was a
programming group in general.
Eric Sosman wrote:
joshc写道:
如果我有我知道要按照递增的顺序排序的数据数组,并且数组少于50个元素,我想找到
第一个元素大于某个值,是一个简单的线性
在这里搜索最好(从数组的开头到结尾的循环)?似乎
就像其他一些搜索算法一样,比如二进制或者这个数据集上没什么好处。
If I have an array of data that I know to be sorted in increasing
order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple linear search the best here(for loop from beginning to end of array)? It seems like some other search algorithm like binary or whatever would be of no
benefit on this data set.



效率问题真的超出界限<这样的C语言;有很多C的实现和给定操作的时序特性
从一个实现到下一个实现不同。

仍然,对于如此小的数组似乎很可能(不是当然,某些情况下,线性搜索和二进制搜索之间的区别可以忽略不计。当然,找出答案的方法是实现搜索方式和措施。当然,即使这样,结果也只对手头的实施有效,并不一定适合其他人。

-
Eric Sosman
es*****@acm-dot-org.inva lid






这篇关于搜索算法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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