Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Determine the order of magnitude for method 1 implemented in Java below. Unlike the previous question, you do not need to count the total number

Determine the order of magnitude for method 1 implemented in Java below. 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

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

proud of something in particular?

Answered: 1 week ago

Question

8. Describe the steps in the development planning process.

Answered: 1 week ago