213k views
5 votes
The range of a finite nonempty set of $n$ real numbers $S$ is defined as the difference between the largest and smallest elements of $S$. For each representation of $S$ given below, describe an algorithm in pseudo code to compute the range. Indicate the time efficiency classes of these algorithms using Big-$O$.

User Bob Kerns
by
4.1k points

1 Answer

3 votes

Answer: Hello your question is poorly written attached below is the well written question

answer:

a) Determine ( compute ) the difference between the max and minimum value. determine the Min and max values using 1.5n comparisons

time efficiency = θ( n )

b) A(n-1) - A(0)

time efficiency = θ( 1 )

Step-by-step explanation:

a) An unsorted array

To find the maximum and minimum values scan the array of elements , then determine ( compute ) the difference between the max and minimum value. to determine the range. Alternatively determine the Min and max values using 1.5n comparisons

Algorithm's time efficiency = θ( n )

b) A sorted array

To determine the range, we will determine the difference between the first and last element i.e. A(n-1) - A(0)

time efficiency = θ( 1 )

The range of a finite nonempty set of $n$ real numbers $S$ is defined as the difference-example-1
User Artur Gaspar
by
3.3k points