1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is linear search?
A search method that checks each item one by one from start to end.
What is binary search?
A fast search that repeatedly checks the middle of a sorted list.
What kind of list does binary search require?
A sorted list (numbers or items must be in order).
What are the starting values of low and high in binary search?
low = 0, high = len(list) - 1
How do you find the middle index in binary search?
mid = (low + high) // 2
When does binary search stop?
When the target is found, or when low > high.
What does binary search return if it finds the item?
The index of the item.
What does binary search return if it doesn't find the item?
None (or -1, depending on the code).
What is the time complexity of linear search?
O(n) — slower for large lists.
What is the time complexity of binary search?
O(log n) — much faster than linear for big lists.
What does log₂(n) tell you in binary search?
How many times you can cut the list in half before it's empty.
Binary vs. Linear Search: which is faster for large lists?
Binary search — but only if the list is sorted.
Why does binary search fail on unsorted lists?
Because the logic assumes sorted order to skip parts of the list.