What is the order of complexity of the following function in
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](/WebImages/35/what-is-the-order-of-complexity-of-the-following-function-in-1105621-1761585087-0.webp)
![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](/WebImages/35/what-is-the-order-of-complexity-of-the-following-function-in-1105621-1761585087-1.webp)