Sorting and searching Flashcards
1
Q
Explain the function of the linear search technique
A
It traverses the entire array and compares each value with the search value. If a match is found it returns the index or an approprate message
2
Q
Explain the function of the binary search technique
A
Array must be first sorted.
The binary search then finds the midpoint of the indexes and compares it with the search value. If the search value is a match it will return that index. If the value is higher then low = mid+1 and if the value is lower high = mid -1 these processes will be repeated until the value is found or until low is greater than high