Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference between time complexity O(ab) and O(N^2)

I assume that this code ideally representation of O(n^2) complexity. The reason is for function in another for function

for (int i = 0; i < array. length; i++) 
    for (int j = 0; j < array.length; j++) 
             System.out.println(array[i] + "," + arrayfj]); 

Also, I read that code below is represent O(ab) time complexity. But why is that way? I don’t undersant, because if (arrayA[i] < arrayS[j]) , this is constant and we can ignore that.

for (int i = 0; i < arrayA.length; i++) 
   for (int j = 0; j < arrayB.length; j++) 
       if (arrayA[i] < arrayS[j]) 
           System.out.println(arrayA[i] + + arrayBfj]); 

This also mentioned as O(ab), although for (int k = 0; k < 160800; k++) is also as constant

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for (int i = 0j i < arrayA.length; i++)
       for (int j = 0; j < arrayB.length; j++)
          for (int k = 0; k < 160800; k++) 
             System.out.println(arrayA[i] + "," + arrayB[j]);

Different sites write different information about it.

>Solution :

If the first case, each array is the same length (n), and n*n prints are done.

In the second, the sizes of the arrays are a & b, and a*b ifs are done, and (potentially) that many prints are done (maybe everything in A is less than everything in B).

In the thirs, the sizes of the arrays are a & b, and (a*b)*160800 prints are done, but the constant can be ignored.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading