Suppose there is a pyramid like
5
4 3
2 3 1
8 3 2 2
7 8 9 1 2
I want to find the path in this pyramid so that the sum of the numbers in that path is maximum. I can move to next row either left or right. as i am at 5 then i can move to 4 or 3. if am at 4 then i can move to 2 or 3. Answer should be the maximum sum only.
If there are no restrictions on the values each node can have, then you'll essentially need to traverse every possible path and calculate the sum of each path.
1) Create a jagged array of int for the pyramid and populate with the values.
2) Create an array to hold the indicies in the rows which result in the highest total.
3) Loop round the first array array top to bottom and cacluate the total.
4) Set this total = highest total, set array og highest indicies = indices used.
5) Repeat loop down jagged array with 1 index different on 1 of the sub-arrays.
6) If total > highest, assign to highest and reset indicies store.
7) repeat for every combination.