MHB Finding values in a 2 dimensional array

  • Thread starter Thread starter fvnn
  • Start date Start date
  • Tags Tags
    Array
AI Thread Summary
The discussion focuses on calculating values in a two-dimensional array B based on the sums of elements from a one-dimensional array A. The pseudo code provided iterates through indices to populate B[i][j] with the sum of A[k] for k ranging from i to j. An example is given where, for i=1 and j=3, B[1][3] equals 6 after summing A[1], A[2], and A[3]. Participants suggest executing the code manually and implementing it in a programming language like C for verification. The conversation emphasizes understanding array indexing and the summation logic.
fvnn
Messages
2
Reaction score
0
Here's the pseudo code:

Code:
for i := 1 to n { //i=1 and n=4
  for j := i to n { //j=1
   B[i][j] := 0
     for k := i to j {
       B[i][j] := B[i][j] + A[k]
     }
  }
}

This is what i understand from the code above - B values are from the sum of a values.
I want to know what the values of B[j] would be if A were A[1,2,3,4]. I don't need an answer i just need guidance on how to solve this.
 
Technology news on Phys.org
Do array indices start at 1?

Why don't you execute the code by hand and then write an actual program, say, in C to verify the result? For example, when $i=1$ and $j=3$ the inner loop makes three iterations:

B[1][3] := B[1][3] + A[1];
B[1][3] := B[1][3] + A[2];
B[1][3] := B[1][3] + A[3];

So the B[1][3] ends up with 1 + 2 + 3 = 6.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top