Question: Consider the following definitions: void func(int arr[], int n) { int i, j; i = 0; j = n-1; while (i < j) {

Consider the following definitions: void func(int arr[], int n) { int i,

 

Consider the following definitions: void func(int arr[], int n) { int i, j; i = 0; j = n-1; while (i < j) { while((arr[i] < 0) && (i < j)) i += 1; while((arr[j] >= 0) && (i < j)) j = 1; if(i < j) { swap (arr[i], arr[j]); i += 1; } j -= 1; } } void swap (int x, int& y) { int temp; temp = x; x = y; y = temp; } Analyze its running time of func. Explain your answers. Notes: 1. The function's parameter n represents the logical size of arr. n is the input size of this function. 2. Give your answers in terms of asymptotic order. That is, T(n) = O(n), or T(n) = 0 (n), etc.

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 Programming Questions!