Question: A = [ [3], [7, 4], [2, 4, 6], [8, 5, 9, 3] ] function findLargestPath(triangle, row, col) { // Check to see if the

A = [

[3],

[7, 4],

[2, 4, 6],

[8, 5, 9, 3]

]

function findLargestPath(triangle, row, col) {

// Check to see if the row and column are actually in the triangle

if (col == -1 || col >= triangle[row].length) {

return -1; //If they are not. ensure that this path wont be taken.

}

if (row == triangle.length - 1) {

return triangle[row][col]; //Return the value.

} else {

//return this value plus the maximum path below

return triangle[row][col] + Math.max(findLargestPath(triangle, row + 1, col), findLargestPath(triangle, row + 1, col + 1));

}

}

console.log(findLargestPath(A, 0, 0));

Why recurrence of this algorithm is T(n)=2T(n-1)+O(1)

Please explain with sufficient details

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!