Question: Recall that for integers a_1, ..., a_n and an integer x, LinearSearch(x, a_1, ..., a_n) returns the index of x if x is one of

Recall that for integers a_1, ..., a_n and an integer x, LinearSearch(x, a_1, ..., a_n) returns the index of x if x is one of the elements of the list a_1, ..., a_n or returns 0 if x is not part of the list. LinearSearch has a runtime of Theta (1) in the best case, and Theta (n) in the worst case. Recall that for a sorted list of integers a_1, ..., a_n and an integer x, BinarySearch(x, a_1, ..., a_n) also returns the index of x if x is one of the elements of the list or returns 0 if x is not part of the list. BinarySearch has a runtime of Theta (log(n)) in all cases. (a) Consider the following two search algorithms: procedure Search(x, a_1, ..., a_n) return LinearSearch(x, a_1, ..., a_n) procedure Search2(x, a_1, ..., a_n) s_1, ..., s_n = SmartSort*(a_1, ..., a_n) return BinarySearch(x, s_1, ..., s_n) (* Assume that Smart Sort has a runtime of Theta (n log(n)) in all cases.) i. Use Theta notation to describe the runtimes of Search1 and Search2 in the best case. Which algorithm is more efficient in the best case? Justify your answers. ii. Use Theta notation to describe the runtimes of Search1 and Search2 in the worst case. Which algorithm is more efficient in the worst case? Justify your answers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
