For instance, consider a 2D array arr[][] of size 4x4 structured as follows: arr[4][4] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} Step 1: Construct the Prefix Sum Matrix: dp[4][4] = {1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16} Each element in dp signifies the total of all cells that are above and to the left of it, including the cell itself. Step 2: Compute the sum of a sub-matrix: For example, let's determine the sum of the sub-matrix from (1,1) to (2,2). We apply the formula: Sum = dp[2][2] - dp[0][2] - dp[2][0] + dp[0][0] = 9 - 3 - 2 + 1 = 5. And there you have it! We obtained the sum in constant time.