Week 3: Linear (Sequential) Search 2. Binary Search 3. Complexity of Algorithms
Week 3: Linear (Sequential) Search 2. Binary Search 3. Complexity of Algorithms
How?
– Proceeds by sequentially comparing the key with
elements in the list
– Continues until either we find a match or the end
of the list is encountered.
– If we find a match, the search terminates
successfully by returning the index of the element
– If the end of the list is encountered without a
match, the search terminates unsuccessfully.
1. LINEAR (SEQUENTIAL) SEARCH
{find =i;
break;}
return find;
} average time: O(n)
2. BINARY SEARCH
Linear Search
– O(n).
Binary Search
– O(log2 N)