what is the difference between the Big O of sum(A) & full (sum (A)) ????????
1 view (last 30 days)
Show older comments
mai saad
on 26 Dec 2015
Answered: Walter Roberson
on 26 Dec 2015
matrix A(n*n) what is the difference between the Big O of computing sum(A) & full (sum (A)) ??????
0 Comments
Accepted Answer
Walter Roberson
on 26 Dec 2015
If the matrix is not sparse then the times are the same, O(n^2)
If the matrices are sparse, then the time of sum(A) is potentially O(Nz) where Nz is the number of non-zero values in the matrix. Then full(sum(A)) is going to require filling out the sparse row vector, and the time for that is going to be at least n (number of columns) because each column in the output would have to be written to; in practice it would be more like (n + p) where p is the number of non-sparse columns, which is a value you cannot directly compute from knowing the number of non-sparse elements of A (but you can apply the pigeon-hole principle to put a lower bound on it as ceiling(Nz/p)) . Assuming a best-case implementation rather than a practical implementation, call it n, so the overall order would be n+Nz where n is number of rows and Nz is number of non-zero entries (which is going to be between 0 and n^2). Best case is O(n), worst case is O(n^2).
0 Comments
More Answers (0)
See Also
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!