2.3.4 - Searching Algorithms Flashcards
What is a search algorithm?
An algorithm used to find a specified element within a data structure.
How does a binary search work?
It works by finding the middle element in a list of data before deciding which side of the data the desired element is to be found in. The unwanted half is then discarded and the process is repeated until the desired element is found.
What needs to be done before doing a binary search?
The list needs to be sorted.
What is the time complexity of a binary search algorithm?
O (log n).
How does a linear search work?
It searches through each element in an array until the desired search criteria is found.
What is the time complexity of a linear search algorithm?
O (n).