Question
Determine the order of magnitude for method 1 implemented in java as below. This method sorts an array of integers in a descending order. Unlike
Determine the order of magnitude for method 1 implemented in java as below. This method sorts an array of integers in a descending order. Unlike the previous question, you do not need to count the total number of statement executions to come up with a precise big-Oh; instead, you can use the shortcut rules covered in the lecture for computing the big-Oh. Notice that method 1 includes a statement that calls method 2.
public static int method1(int arr[], int diff) { int count = 0; for(int i = 0; i < arr.length; i++) { int num = arr[i] - diff; boolean hasNum = method2(arr, i+1, num); if(hasNum) { count += 1; } } return count; } public static boolean method2(int arr[], int index, int d) { for(; index < arr.length; index += 1) { if(arr[index] == d) { return true; } } return false; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started