在一列给定的值中进行搜索,从一端开始逐一检查每个元素,直到找到所需元素的过程。 线性查找又称为顺序查找 如果查找池是某种类型的一个表,比如一个数组,简单的查找方法是从表头开始,一次将每一个值与目标元素进行比较,最后,或者查找到目标,或者达到表尾,而目标不存在于组中,这个方法称为线性查找。 #include
在许多实现中,实行的是代价很高的线性查找。
In many implementations they will perform costly linear searches.
在CSimpleBinaryTree 中有两个搜索算法.线性搜索和对半搜索.线性搜索只在树种子项数目小于指定值的时候才使用 (缺省为10),从这个点以后的各项,将使用对半搜索.这样做的原因是线性查找不要求元素进行排序并且它的运算规则相对要简单的多.因此对于小数目项来说,线性查找是理想的.
The reason for this is that a linear search doesn't require the elements to be sorted and its algorithm is a lot less complicated. So for a small number of items a linear search is ideal.
在这种情况下,按名称查找属性会进行线性搜索。
In this case, looking up an attribute by name initiates a linear search.
If I look for, say, minus 1, you might go, gee, wait a minute, if I was just doing linear search, I would've known right away that minus one wasn't in this list, because it's sorted and it's smaller than the first elements.
如果我要查找-1,你可能要怒了,呵呵,等一等,如果我用的是线性查找,我不会知道-1不在这个列表中,但是列表是排好序的,1又比第一个元素小。
Right? If that was the case in that code, then my complexity is no longer log, because I need linear access for each time I've got to go to the list, and it's going to Lisp be much worse than that.
这里的复杂度不再是对数的了,因为每次在列表中,查找需要线性访问,可能还要糟糕,其实,有些编程语言,如。
And if you just look at the numbers, you can see how it cuts in from one side and then the other side as it keeps narrowing that range until it gets down to the place where there are at most two things left, and then it just has to check those two to say whether it's there or not.
你能看到他是如何不断的,从一个大的范围被拦腰劈开,知道最终只剩下两个数字,然后就只需要,比一比就知道结果了,将它同线性查找比较下。
在一列给定的值中进行搜索,从一端开始逐一检查每个元素,直到找到所需元素的过程。 线性查找又称为顺序查找 如果查找池是某种类型的一个表,比如一个数组,简单的查找方法是从表头开始,一次将每一个值与目标元素进行比较,最后,或者查找到目标,或者达到表尾,而目标不存在于组中,这个方法称为线性查找。 #include
应用推荐