Question: (d) Consider the following algorithm to find the smallest item in a list of n distinct integers: 1. Pick an element, x, from the list
(d) Consider the following algorithm to find the smallest item in a list of n distinct integers: 1. Pick an element, x, from the list at random. 2. Go through every other element in the list. If an element is less than x put it in list 1, and if it's more than x, put it in list 2. (Note: Since all elements in the list are distinct, none will equal to x.) 3. If list 1 is empty, then return x, since it's the smallest element. If list 1 is NOT empty, go back to the first step, only using list 1. In terms of n, what is the best case run-time of this algorithm? In terms of n, what is the worst case run-time of this algorithm? Justify both answers in words. [10 marks]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
