Question: 15] 2. Below is an algorithm which (naively) counts the number of distinct elements in an array of n integers. Every element in the array

 15] 2. Below is an algorithm which (naively) counts the number

15] 2. Below is an algorithm which (naively) counts the number of distinct elements in an array of n integers. Every element in the array is compared to the previous entries. If it is not found among these entries, the count (of distinct elements) is increased by 1. (a) Determine the worst-case time-complexity function f(n) in terms of the array size n and find the best big-oh approximation of f. Algorithm: Distinct Element Count Input: An array of integers 21, 22, ..., Output: The number of distinct elements count=0 for 1 to n do found false for j - 1 to 1-1 do | if rysy then found true end if found false then count count + 1 end return count Note: The Inner for loop does not run if the end value - 1 is smaller than the start value 1 (which happens when - 1). (6) What would change in a best-case Analysis? Is the best big-oh approximation different than in the worst case Note: This can be answered in a few sentences do not write paragraphs of explanations

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!