3.1.3 - Searching algorithms Flashcards
(8 cards)
Linear search
A linear search checks each item in a list one by one until the desired item is found or the end of the list is reached.
Binary search
A binary search repeatedly divides a sorted list in half to find the desired item more efficiently.
What are the advantages of a linear search?
Works on unsorted lists
No need for complex algorithms
What are the disadvantages of a linear search?
Can be slow for large lists
Inefficient compared to binary search on sorted data
What are the advantages of a binary search?
Faster than linear search for large, sorted lists
What are the disadvantages of a binary search?
Requires the list to be sorted
More complex to implement than linear search
When is a linear search more appropriate than a binary search?
When dealing with small or unsorted lists
When is a binary search more appropriate than a linear search?
When dealing with large, sorted lists where search efficiency is important.