Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this task, we want to find a smallest element in an unordered array. (b) Consider Algorithm B. Algorithm 1: Algorithm B Input: array a[1..n]

In this task, we want to find a smallest element in an unordered array.image text in transcribedimage text in transcribed

(b) Consider Algorithm B. Algorithm 1: Algorithm B Input: array a[1..n] Output: the position of a smallest element minPos = 1 j=1 while j a[j + 1] then L minPos = j +1 j=j +1 return min Pos i. (1 point) Formulate an invariant depending on a, j and minPos. Use the invariant to argue that the algorithm is correct. ii. (1 point) How often does the algorithm compare two elements of a (that is, a[minPos] > 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 algorithm for n= 1000 000 on your computer? (c) (1 point) Discuss why any algorithm needs at least n - 1 comparisons to find a minimum element in the worst case<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

Students also viewed these Databases questions

Question

76 Leadership concepts and applications.

Answered: 1 week ago