15 day fast algorithm series -- the fourth day five classic search [1]
In our life, there is no place where there is no search. For example, find out which mm is the most pl at work, guess the age of MM... All these are search.
In our algorithm, one is called linear search.
Divided into: sequential search.
Half search.
There are two forms of searching:
Divided into: destructive search, such as a group of mm, I guess their age, the first guess is 23 +, at this time this mm has been remove d from the mmlist in my mind.
Brother doesn't find 23 +, so this kind of search destroys the original structure.
Non destructive search, on the contrary, does not destroy the structure.
Order lookup:
This is very simple, that is, after an array, one by one ratio, until we find it.
Half search: this kind of search is very interesting, that is to cut off half every time,
For example, in the "lucky 52" price guessing game, the price is below 999 yuan. You can guess how many to give in one minute. If those players know how to search in half,
That's quite the result.
Note, however, that there are two disadvantages to this search:
First: arrays must be ordered. If they are not, they must be ordered. You know that the fastest sorting is NLogN, so.
Second, this search is limited to linear sequential storage structures.
Upper Code:
As we have said before, there is a form of searching that is destructive, so it is very sad for the data of linear structure, because every time it is broken,
It may cause the whole array element to move forward or backward.
So the search of linear structure is not suitable for destructive operation. Is there any other way to solve it? Well, there must be, but I'll share it the next day.
ps: linear search time complexity: O(n);
The time complexity of half disorder (with fast live stacking): O(NlogN)+O(logN);
Half ordered time complexity: O(logN);