简体   繁体   中英

What it's the time complexity of 2D array not strictly square?

Let's assume we have a 2D array that looks like this

array = [[1,2,3],
         [4,5,6]] 

As you can see, it's not a square 2D array, and we have a function that sums all the values in it.

def sum_values(array):
     total = 0
     for i in array:
         for j in i:
             total += j
     return total
      

So the question is, is the time complexity still O(n^2)? or something like O(ab) or something else?

you can define n as the size of the input matrix and say the algorithm is O(n) or you can define n as the number of rows and m as the number of columns in the input and say the algorithm is O(n*m)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM