Модуль: Calculation of asymptotic complexity


Задача

1/9

Calculation of asymptotics - 1

Теория

Error

Задача

For the code below, find the asymptotics: int func(vector <int> arr) { intn = arr.size(); int max1 = INT_MIN, pos1 = -1; for (int i = 0; i < n; i++) { if (arr[i] > max1) { max1 = arr[i]; pos1 = i; } } int max2 = INT_MIN, pos2 = -1; for (int i = 0; i < n; i++) { if (i == pos1) continue; if (arr[i] > max2) { max2 = arr[i]; pos2 = i; } return max2; }
1) O(1)
2) O(log(n))
3) O(n)
4) O(n^2)

 

Выберите правильный ответ, либо введите его в поле ввода

Комментарий учителя