What is the order of complexity of the following function in

What is the order of complexity of the following function? int Mystery(int start, int end, int a, int array[]) int index 1, index2; index 1 = (end-start)/3+start; index2 = (2*(end-start))/3+start; if(start == end) if(start == end) return start; else {if(array[index 1] Less than a) return Mystery(start, index 1, a, array); else if((array[index 1] Greater than = a) && (array[index2] Less than a)) return Mystery(index1, index2, a, array); else return Mystery(index2, end, a, array);

Solution

Hello,

I guess the Order of complexity somehow means Probability of execution of functions. I have tried to give a picture of my understanding by explaining the things as below,

The Order of Java functions getting complexity level is as below with 1 as lowest and 4 as highest.

Order

Category

Functions – Add one for each of following

1

Returns

Each return that isn\'t the last statement of a method.

2

Selection

if, else, case, default.

3

Loops

for, while, do-while, break, and continue.

4

Operators

&&, ||, ?, and, :

For the given function, below is the complexity level with Highest to lowest order shown

4. Else If ((array [index 1] >= a ) && (array [index 2] < a))

    return Mystery (index 1, index 2, a, array)

3. if (array [index 1] < a)

    return Mystery (start, index 1, a, array)

2. if (start == end)

    return start

1. index 2 = (2*(end-start))3+start and then index 1 = (end-start)/3+start

Please share your feedback for the explanation. Was it helpful in some manner or not.

Order

Category

Functions – Add one for each of following

1

Returns

Each return that isn\'t the last statement of a method.

2

Selection

if, else, case, default.

3

Loops

for, while, do-while, break, and continue.

4

Operators

&&, ||, ?, and, :

 What is the order of complexity of the following function? int Mystery(int start, int end, int a, int array[]) int index 1, index2; index 1 = (end-start)/3+sta
 What is the order of complexity of the following function? int Mystery(int start, int end, int a, int array[]) int index 1, index2; index 1 = (end-start)/3+sta

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site