Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
5] 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 1], 22, ..., In Output: The number of distinct elements count 0 for i 1 to n do found false + 1 to i-1 do | if x; = x, then found + true end if found false then count count +1 end return count for j Note: The inner for loop does not run if the end value i - 1 is smaller than the start value 1 (which happens when i 1). (b) 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

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

To find integral of sin(logx) .

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago