Moderators: phlip, Larson, Moderators General, Prelates
Yakk wrote:Computer Science is to Programming as Materials Physics is to Structural Engineering.
_Axle_ wrote:My 2 cents on this matter is that its a O(n), since this is a matrix. Yes, it is a double loop, but that is part of how the matrix logically setup for human reading. If you set up your private data to be m_data[n*m] , you can just do a single loop.
phlip wrote:It depends on what you call "n". It's O(n2) in the width or height of the matrix, but O(n) in the number of elements in the matrix. Since the number of elements in the matrix is the square of the width or height, it should be clear that both of these are the same.
Usually, the complexity is given in terms of "the size of the input"... which in this case, would be the number of values in the matrix. So you'd call it O(n) in terms of the size of the input.
Dolus wrote:Let's assume we have an m*m graph. In the example below, it's a 4x4 matrix, so there are 16 cells.
...
m * m where m = 4, so 16 cells
skelterjohn wrote:For matrix algorithms, the way the size of the input is characterized is typically the maximum of width and height, rather than the total number of elements.
k2daevin wrote:skelterjohn wrote:For matrix algorithms, the way the size of the input is characterized is typically the maximum of width and height, rather than the total number of elements.
this is totally correct. the question of the poster was the Big O() notation of this case when using a nested for loop on all the elements.
k2daevin wrote:skelterjohn wrote:For matrix algorithms, the way the size of the input is characterized is typically the maximum of width and height, rather than the total number of elements.
this is totally correct. the question of the poster was the Big O() notation of this case when using a nested for loop on all the elements.
ask your teachers/professors. if any of them doesn't say N^2, then revoke their license!
Dolus wrote:the input size does increase as m^2 (grows quadratically? Is that the right word?)
SippyCup wrote:OP answered his own question here: "the runtime still increases linearly with the increase of input size."
Linear means O(n).
Sana wrote:Linear means O(n), but increasing linearly means O(n^2). The rate of increase refers to the derivative, not the function itself.
Users browsing this forum: No registered users and 2 guests