Algorithm to efficiently determine the [n][n] element in a matrix

前端 未结 6 453
半阙折子戏
半阙折子戏 2020-12-30 07:07

This is a question regarding a piece of coursework so would rather you didn\'t fully answer the question but rather give tips to improve the run time complexity of my curren

6条回答
  •  灰色年华
    2020-12-30 07:46

    If the question is about how to output all values of the function for 0<=i, 0<=j, here is a solution in time O(N²) and space O(N). The time behavior is optimal.

    Use a temporary array T of N numbers and set it to all ones, except for the first element.
    
    Then row by row,
    
        use a temporary element TT and set it to 1,
        then column by column, assign simultaneously T[I-1], TT = TT, (TT + T[I-1] + T[I])/3.
    

提交回复
热议问题