Chapter 3: Q7RE (page 232)
a.) Describe the linear search and binary search algorithm for finding an integer in a list of integers in increasing order.
b.) Compare the worst-case time complexities of these two algorithms.
c.) Is one of these algorithms always faster than the other (measured in terms of comparisons)?
a.) Describe the linear search and binary search algorithm for finding an integer in a list of integers in increasing order.
b.) Compare the worst-case time complexities of these two algorithms.
c.) Is one of these algorithms always faster than the other (measured in terms of comparisons)?
Short Answer
a.) Linear search searches for the integer by comparing the integer with the first element in the list, then with the second element, then the third and so on. If the element is found, then the algorithm stops and the position of the element is returned.
b.) Linear:
Binary:
c.) No