Simple question. Working with an m x n matrix and I'm doing some O(mn) operations. My question is if O(mn) is in O(n^2). Looking at the Wikipedia on big O I would think so but I've always been pretty bad at complexity bounds so I was hoping someone could clarify.
O(mn) for a m x n
matrix means that you're doing constant work for each value of the matrix.
O(n^2) means that, for each column, you're doing work that is O(# columns). Note this runtime increases trivially with # of rows.
So, in the end, it's a matter of if m
is greater than n
. if m >> n, O(n^2) is faster. if m << n, O(mn) is faster.
m * n
is O(n2) if m
is O(n).
I assume that for matrix you probably will have m
= O(n) which is the number of columns while n
is a number of rows. So m * n
= O(n2). But who knows how many columns your matrix will have.
It all depends on what bounds does m
have.
Have a look at definition of O(n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With