1. Engineering
  2. Computer Science
  3. 5 50 points arrange numbers in an equilateral triangle with...

Question: 5 50 points arrange numbers in an equilateral triangle with...

Question details

5) (50 points) Arrange numbers in an equilateral triangle with n numbers at the base, like the one shown below for n - 4. The problem is to find the smallest sum in a descent from the triangles apex to its base through a sequence of adjacent numbers. 2 4 7 8 6 6 (Note that 4 in the second row has two adjacent numbers in the third row: 3 and 7, but not 1.) Thus, for the triangle above the minimal sum is 2+516 14. Store the elements of the triangle in an arrayA [i,Л. indexed top-to-bottom by rows 1-1, , n and left-to-right by columns j : 1, , 1. a) What is the size of the triangle as a function of n? In the above example, the size is 10. What is the relationship between adjacent elements of the triangle in terms of i and j? In the example above, the item 4-A[2 2] is adjacent to the items 3-A32and-A33 below it write your answer in the form A [i, Λ is adjacent to elements AL J and AL J below, for i <-. b) c) Solve this problem using dynamic programming by writing down its recurrence equation. Hint the initial conditions are S[n,Л-A[n,Л forj-1, , n and the final result is to return ș[1,1].

d) Explain how to solve this problem by the greedy method. Hint: connect the numbers to form a weighted graph and use an algorithm we already covered in class. e) Is the greedy approach more efficient than the dynamic programming solution? Explain.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution