Linear search
Searching for a value by looking at the elements one by one, from the start, until you find it. It costs O(n).
Example
To find 42 in an unsorted list of 1,000 numbers, in the worst case you look at all 1,000.
Test yourself: Linear search
Arrays
What's the complexity of searching for a value in an unsorted array?
The address calculation works if you know the position, not the value. To find 42 among 1,000 unsorted, up to 1,000 steps.
Choosing how to search
Brute-force search costs O(___).
It looks at elements one at a time: with 50,000 items, in the worst case, 50,000 steps.
Choosing how to search
A list of 15 tasks changes every minute and you search for 1 now and then. What do you use?
15 comparisons now and then are nothing. Maintaining a hash or tree on every change would be extra work.
0/3
â–¶ Play