147k views
3 votes
Given list: {172430364453586872 \} Which list elements will be checked to find the value: 17 using binary search? 17 using linear search? 44 using binary search? 44 using linear search? Which search method is faster to find 17 ? Which search method is faster to find 44 ?

User Imwilsonxu
by
8.5k points

1 Answer

4 votes

Final answer:

To find a value in a list, binary search is generally faster than linear search on a sorted list because it systematically halves the searchable area, whereas linear search goes through each element sequentially until the target is found. The exact elements checked during a binary or linear search would depend on the list content and the position of the target value.

Step-by-step explanation:

When searching for a value in a sorted list using binary search, you would typically start by examining the middle element and then, depending on whether the target value is greater or smaller, you continue the search in the appropriate half of the list. This process is repeated, halving the list size each time until the target is found or the size of the remaining portion is zero. For linear search, all elements are checked in sequence until the desired value is found.

To find the value 17 using binary search, the steps may involve checking these middle values in sequence: 23, then 12, 17. For linear search, each element would be checked in order starting from the first one, resulting in potentially checking all the elements up to 17. To find the number 44, the binary search would involve checking values 23, 34, and possibly a few more depending on its position in the list, while linear search would again involve checking each element one after the other until 44 is reached.

Binary search is faster than linear search for finding the number 17 if the list is sorted because it drastically cuts down the number of comparisons needed to find the target value. Linear search could be faster for finding the number 44 depending on its position in the list; if it's early in the list, fewer checks are needed compared to binary search which may require checking multiple middle points.

User Telemachus
by
7.8k points