Я хочу найти Big O метода1.Как рассчитать Big O для этого алгоритма?
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, int last)
{
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
Мое мышление заключается в том, что нам не нужно заботиться о privateMethod1, это правда? Не нужно ли беспокоиться о вызовах функций при вычислении Big O и просто учитывать другие факторы, такие как операции присваивания в нашем методе1?
Спасибо.
Нет, вам обязательно нужно учитывать время работы других функций, когда они вызывают в вашем алгоритме. –
О, хорошо. Спасибо, что сообщили мне об этом. –