比如说我有数组data,1000个元素,要从里面找x,线性搜索,就是从头找到尾,依次来看data是否等于x,如果不是data,data,依次类推,一直找到最后一个。速度最慢,但是适用性最广。
但这是一个线性搜索。
在这种情况下,按名称查找属性会进行线性搜索。
In this case, looking up an attribute by name initiates a linear search.
考虑,举个例子,怎么写一个算法执行线性搜索一个区域。
Consider, for example, how to write an algorithm that performs linear search through a range.
If it was an unordered list, we were basically stuck with linear search. Got to walk through the whole list to see if the thing is there.
如果是一个未排序的列表,基本上我们就只能使用线性搜索了,通过遍历整个列表来查看。
And what does that say? It says, let's assume I want to do k searches of a list. OK.
如果我们假定要在列表中做k次搜索,在线性的情况下,假定是一个未排序的情况。
So, as the gentleman back there said, if I'm searching it once, just use the linear search.
如果我就搜索一次,就用线性搜索吧,另一方面。
应用推荐