Question: Task 1.4: In this task, we want to find a smallest element in an unordered array. (a) Consider Algorithm A. Algorithm 0: Algorithm A Input:

 Task 1.4: In this task, we want to find a smallest

Task 1.4: In this task, we want to find a smallest element in an unordered array. (a) Consider Algorithm A. Algorithm 0: Algorithm A Input: array a[1..n] Output: the position of a smallest element minPos = 0 i=1 while min Pos == 0 do min Pos = i j=1 while j a[j] then minPos = 0 j=j +1 i=i+1 if i>n then i=1 return min Pos i. (1 point) Does the algorithm terminate? If not, fix the error and argue why it now terminates. ii. (1 point) How often does the (fixed) algorithm compare two elements of a (that is, a[i] > a[j]) in dependence of n in the worst case? Further, suppose that the running time depends only on comparing two elements of a. Further suppose that your computer can compare two elements of a in one millisecond. What is the worst case running time of the (fixed) algorithm for n = 1000 000 on your computer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!