Which statement correctly compares linear search and binary search?

Master computer concepts with our module 2 exam study guide. Engage with interactive quizzes, detailed questions, and comprehensive explanations to ace your test. Prepare effectively for computer skill proficiency!

Multiple Choice

Which statement correctly compares linear search and binary search?

Explanation:
Binary search relies on the data being in sorted order and uses a divide-and-conquer approach: compare the target with the middle element, then discard half of the remaining items and repeat. Because each step halves the search space, the number of steps grows with log2(n), giving O(log n) time. Sorting is necessary before binary search to guarantee that halving correctly eliminates the wrong half. Linear search doesn’t require any ordering; it checks elements one by one until it finds the target or reaches the end. Its worst-case time is O(n), but you don’t need to sort the data for it to work. So the correct statement is that binary search is O(log n) and requires the data to be sorted. The other claims are not accurate because linear search does not require sorting, and binary search does require sorting to function properly.

Binary search relies on the data being in sorted order and uses a divide-and-conquer approach: compare the target with the middle element, then discard half of the remaining items and repeat. Because each step halves the search space, the number of steps grows with log2(n), giving O(log n) time. Sorting is necessary before binary search to guarantee that halving correctly eliminates the wrong half.

Linear search doesn’t require any ordering; it checks elements one by one until it finds the target or reaches the end. Its worst-case time is O(n), but you don’t need to sort the data for it to work.

So the correct statement is that binary search is O(log n) and requires the data to be sorted. The other claims are not accurate because linear search does not require sorting, and binary search does require sorting to function properly.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy