Page 1 of 1

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

Posted: Fri Jul 01, 2022 5:41 am
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