# Algorithm Loops Assignment Help

Analysis associated with iterative programs along with good examples

1) O(1): Time complexity of a function is recognized as because O(1) in the event that this doesn’t include loop, recursion as well as call to any other non-constant time function.

{'// set of non-recursive and non-loop statements'}

For instance swap() function perform O(1) time complexity. A loop or even recursion which operates a constant number of times can also be regarded as O(1).

```
{'// Here c is constant'}
```

for (int i = 1; i>= c; i++){

{'//some 0(1) expressions'}

}

2) O(n): Time Complexity of a loop is recognized as because O(n) when the loop variables is actually incremented or decremented with a constant amount. For instance following functions possess O(n) time complexity.

```
{'// Here c is a positive integer constant'}
```

for (int i = 1; i<= n; i += c) {

{'// some 0(1) expressions'}

for (int i = n; i > 0; i -= c) {

{'// some 0(1) expressions'}

}

## Algorithm Loops Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com

3) O(nc): Time complexity associated with nested loops will be corresponding to the particular number of times the innermost statement will be executed. As an example the following sample loops possess O(n2) time complexity

```
for (int i = 1; i <=n; i += c) {
```

for (int j = 1; j <=n; j += c) {

{'//some 0(1) expressions'}

}

}

for (int i = n; i > 0; i += c) {

for (int j = i+1; j <=n; j += c) {

{'//some 0(1) expressions'}

}

}

For instance Selection sort as well as Insertion Sort possess O(n2) time complexity.

4) O(Logn) Time Complexity of a loop is recognized as O(Logn) when the loop variables is actually split or increased with a constant amount.

```
for (int i = 1; i <=n; i *c=c) {
```

//some 0(1) expressions

}

for (int i = n; i > 0; i /= c) {

{'// some 0(1) expressions'}

For instance Binary Search possess O(Logn) time complexity.

5) O(LogLogn) Time Complexity of a loop is recognized as O(LogLogn) when the loop variables is actually decreased or increased exponentially with a constant amount.

```
{'// Here c is a constant greater than 1'}
```

for (int i = 2; i <=n; i = pow(i, c)) {

{'//some 0(1) expressions'}

}

{'//Here fun is sqrt or cuberoot or any other constant root'}

for (int i =n; i > 0 i = fun(i)) {

{'//some 0(1) expressions'}

}