What is the worst case time complexity for this algorithm?

algorithm, complexity-theory

Solution

O(n^2), if I read it right.

Why you need two inner loops is beyond me. Why not sum B and C in the same loop?

Problem

``` procedure matrixvector(n:integer); var i,j:integer; begin for i<-1 to n do begin B[i] = 0; C[i] = 0; for j<-1 to i do B[i]<- B[i]+ A[i,j]; for j<-n down to i+1 do C[i]<-C[i] + A[i,j] end end; ```

Original source

Related problems