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
i
in intent iteration. With this, you will only executex
steps and will fall out of the two loops. Not to mention you get to talk aboutn
and 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
x
is the same asn
and the second time isj<x
andj++
and noti
– Francisco Sobrinho