Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started