0
I have a question more mathematical than computational.
Suppose we have a square matrix M of dimension n², where n is any integer greater than zero. Traversing this matrix, assigning j as an index of lines and i to column indexes, what is the complexity of the algorithm if I consider ij only when i>j?
Below the demonstration of the algorithm:
for i=0; i<n-1; i++:
for j=i+1; i<n; j++:
if i>j:
////cont..
I want to know what function to determine, from n, how many times the if will be checked. In other words, how many elements are in the triangular matrix below the diagonal.
*I know it’s a really dumb question, but I completely forgot how to find that function.
(n-1)**2/2, or something very close, I would say.– Jefferson Quesado
By the way, I think there’s something strange about it. In your code, you change the value of
iin intent iteration. With this, you will only executexsteps and will fall out of the two loops. Not to mention you get to talk aboutnand enter in the codex, that is out of context– Jefferson Quesado
It is! Some errors in the algorithm, now that I’ve seen, but it’s just an example of the problem, the
xis the same asnand the second time isj<xandj++and noti– Francisco Sobrinho