Complexity of nested for loops starting from the last iteration

Aram Yeghiazaryan
function solution(A) {
    var len = A.length;
    cnt = 0;
    for(i = 0; i < len - 1; i++){
        for (a = i + 1; a < len; a++){
            if (A[i] == A[a]){cnt++;}
            else{continue;}
        }
        if(cnt > 1000000000){return 1000000000;}
    }
    return cnt;
}

So this is a code for counting identical pairs of an array, I know that 2 for loops give time complexity of O(n2). Is it always the case? Even if the next iteration goes through only remaining part of the array?

Jay

Yes this will be roughly O(1/2n^2) but since constants aren't really that important this will end up being O(n^2)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Complexity of An Algorithm(Nested loops)

From Dev

Finding the Complexity of Nested Loops

From Dev

Time complexity of nested loops

From Dev

Calculating complexity of nested loops

From Dev

Time complexity for nested loops?

From Dev

Complexity in tilde notation of nested for loops

From Dev

Time Complexity of the given nested loops

From Dev

Time complexity of nested loops with if statement

From Dev

Time complexity of an algorithm with nested loops

From Dev

TIme complexity of various nested for loops

From Dev

Time Complexity of the given nested loops

From Dev

Determining the time complexity of these nested loops

From Dev

Python file iteration and nested for loops

From Dev

Timestables from the nth number to the last input using nested for loops in java

From Dev

How to determine computational complexity for algorithms with nested loops?

From Dev

Big O complexity of two nested loops

From Dev

Time Complexity of algorithm with nested if statement and for loops

From Dev

nested loops having linear time complexity?

From Dev

Difference of complexity between double nested for loops? (Java)

From Dev

Algorithm time complexity for various nested for loops

From Dev

Algorithm Time Complexity Analysis (three nested for loops)

From Dev

Understanding time complexity in two nested while loops

From Dev

Nested loops causing reduced complexity efficency?

From Dev

Do multiple loops have same complexity as nested loops?

From Dev

R nested loop returning only the last iteration

From Dev

Complexity Of Nested Loop, With Outer Loop Variable Diminishing By Half Each Iteration

From Dev

Complexity of two nested loops with the inner loops stepping dependend on the outer loops variable

From Dev

javascript shows output of only last iteration of for loops with promise object inside

From Dev

Do these two nested loops really have the same quadratic time complexity?

Related Related

  1. 1

    Complexity of An Algorithm(Nested loops)

  2. 2

    Finding the Complexity of Nested Loops

  3. 3

    Time complexity of nested loops

  4. 4

    Calculating complexity of nested loops

  5. 5

    Time complexity for nested loops?

  6. 6

    Complexity in tilde notation of nested for loops

  7. 7

    Time Complexity of the given nested loops

  8. 8

    Time complexity of nested loops with if statement

  9. 9

    Time complexity of an algorithm with nested loops

  10. 10

    TIme complexity of various nested for loops

  11. 11

    Time Complexity of the given nested loops

  12. 12

    Determining the time complexity of these nested loops

  13. 13

    Python file iteration and nested for loops

  14. 14

    Timestables from the nth number to the last input using nested for loops in java

  15. 15

    How to determine computational complexity for algorithms with nested loops?

  16. 16

    Big O complexity of two nested loops

  17. 17

    Time Complexity of algorithm with nested if statement and for loops

  18. 18

    nested loops having linear time complexity?

  19. 19

    Difference of complexity between double nested for loops? (Java)

  20. 20

    Algorithm time complexity for various nested for loops

  21. 21

    Algorithm Time Complexity Analysis (three nested for loops)

  22. 22

    Understanding time complexity in two nested while loops

  23. 23

    Nested loops causing reduced complexity efficency?

  24. 24

    Do multiple loops have same complexity as nested loops?

  25. 25

    R nested loop returning only the last iteration

  26. 26

    Complexity Of Nested Loop, With Outer Loop Variable Diminishing By Half Each Iteration

  27. 27

    Complexity of two nested loops with the inner loops stepping dependend on the outer loops variable

  28. 28

    javascript shows output of only last iteration of for loops with promise object inside

  29. 29

    Do these two nested loops really have the same quadratic time complexity?

HotTag

Archive