What is the time complexity of while loops?

I am trying to find the temporary complexity of while loops, and I have no idea where to start. I understand how to find the complexity class for loops, but when it comes to loops, I'm completely lost. Any tips / hints on where to start?

Here is an example of a problem:

x = 0;
A[n] = some array of length n;
while (x != A[i]) {
   i++;
}
+4
source share
1 answer

- n , n . for, while - , ( -!). , O , , , ( , , , , ).

.


, . for while - , .

, .

:

1. Input n
2. Do OperationX n times

Big O . . , :

1. Input n
2. Input m
3. Repeat m OperationX n times.

Big O , O (n), - O (m * n) ( OperationX ).

, , .

for(int i = 0; i < n; i++) {
    operationX;
}

i = j = 0;
while(i < n) {
    j = 0;
    while(j < m) {
      operationX;
      j++;
    }
    i++;
}

. O , .


A[n] = some array of length n;
for(x = 0;x != A[i];i++) {

}

for (O(n)).

+5

Source: https://habr.com/ru/post/1615295/


All Articles