Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Determine a detailed cost function for the function. This function should be written in the form wnx + yn + z where w, x,

1. Determine a detailed cost function for the function. This function should be written in the form wnx + yn + z where w, x, y and z are real numbers and n is a variable referring to the size of the function's input. If necessary, you should adapt this format to include other terms such as log2(n).

2. Identify (one of) the barometer operations for the function.

3. Identify the O notation running time of the function.

Notes

1. Answer questions 2 to 4 of the General Requirements for the best-case running time of the function

2. Answer questions 3 and 4 (not 2) for the worst-case running time of the function

3. Describe, and give an example of input that constitutes the best and worst case for the algorithm

4. Do not count the actual call to a recursive function as an operation that is you must include the number of operations performed by the recursive call as per rule 2, but the call itself does not count as an operation

// PARAM: arr is array to be sorted, n is size of array, i should initially = 0

void ssort(int arr[], int n, int i) {

if (i < n-1) {

// Find and swap smallest remaining

int next = i + 1;

int smallest = i;

while (next < n) {

if (arr[next] < arr[smallest]) {

smallest = next;

} next++;

}

// Swap i with smallest

int temp = arr[i];

arr[i] = arr[smallest];

arr[smallest] = temp;

ssort(arr, n, i + 1);

}

}

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions