Imagine you have a list of names on a paper. You want to find if the name "Alice" is in the list by checking each name one by one from the start.
Which description best matches this search method?
Think about checking names one by one in order.
Linear search means checking each item in order until the target is found or the list ends.
You have a sorted list: [2, 4, 6, 8, 10, 12, 14]. You want to find the number 10 using binary search.
Which sequence of middle elements will the search check?
Binary search picks the middle element each time and narrows down the search.
First middle is 8, since 10 > 8, search right half. Next middle is 12, since 10 < 12, search left half. Next middle is 10, found target.
Consider this pseudocode for searching a value in a list:
start = 0
end = length(list) - 1
while start <= end:
mid = (start + end) // 2
if list[mid] == target:
return mid
elif list[mid] < target:
start = mid + 1
else:
end = mid - 1
return -1What is the mistake in this binary search implementation?
Think about which half to search next when the middle value is less than the target.
If list[mid] is less than target, the search should continue in the right half, so 'start' must be updated to mid + 1, not 'end'.
Which statement correctly compares linear search and binary search on a sorted list of 1,000,000 items?
Think about how many items each method checks in the worst case.
Binary search reduces the search space by half each step, making it much faster on large sorted lists.
You use binary search to find a number in a sorted list of 1023 elements.
What is the maximum number of comparisons binary search will make before concluding?
Binary search maximum comparisons relate to the power of 2 just greater than the list size.
Binary search maximum comparisons = ceiling of log2(n). For 1023, log2(1023) ≈ 9.99, so max comparisons = 10.