What is the Big Oh of method1? Is there a best case and a worst case? public static void method1(int[] array, int n) { f

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

What is the Big Oh of method1? Is there a best case and a worst case? public static void method1(int[] array, int n) { f

Post by answerhappygod »

What is the Big Oh of method1? Is there a best case and a worstcase?
public static void method1(int[] array, int n)
{
for (int index = 0; index < n - 1; index++)
{
int mark = privateMethod1(array, index, n - 1);
int temp = array[index];
array[index] = array[mark];
array[mark] = temp;
} // end for
} // end method1
public static int privateMethod1(int[] array, int first, intlast)
{
int min = array[first];
int indexOfMin = first;
for (int index = first + 1; index <= last; index++)
{
if (array[index] < min)
{
min = array[index];
indexOfMin = index;
} // end if
} // end for
return indexOfMin;
} // end privateMethod1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply