What is the time complexity of adding three matrices of size NXN cell-by-cell ?



What is the time complexity of adding three matrices of size NXN cell-by-cell ?

A. O(N)

B. O(N2)

C. O(N3)

D. None of these

Answer : B. O(N2)


Explanation :

  • Time complexity will be O(n2), because if we add all the elements one by one to other matrics we have to traverse the whole matrix at least 1 time and traversion takes O(n2) times.
  • With this traversion we add 3 elements of location [ i, j ] and storing the result on other matrix at [ i, j ] location.

Related Searches to What is the time complexity of adding three matrices of size NXN cell-by-cell ?