Question: Writing an algorithm based on resource collection. Please refer to the attached picture. Resource collection is a common problem in Al. The input is a

Writing an algorithm based on resource collection. Please refer to the attached picture.

Writing an algorithm based on resource collection. Please refer to the attached

Resource collection is a common problem in Al. The input is a data structure that contains the benefits (or hazards) for each location on a map. The problem is to plan the best route that maximizes the collected benefits. Note that locations can contain both positive and negative rewards. On a map where each location contains a positive reward (a benefit) the best route would visit each location. On a map where each location contains a negative reward (a hazard) the best strategy would be to not move at all! For our version of the problem the input is an array of n integers that represents a 1 dimensional map. Positive numbers represent benefits while negative numbers represent hazards. You are to write a pseudo-code algorithm that finds the largest possible sum from visiting a contiguous sequence of array elements. The route can start at any element of the array. Your algorithm should be documented with comments. You should also determine the running time of your algorithm using O notation as a function of the size of the input array, n. There are marks assigned to efficiency so the faster your algorithm runs, the better your grade. For A = {5, -6, 7, -5, 10, -1} -the best sum consists of the values in A{2, 4} for a total of 7 + -5 + 10 + 12 For A = {1, 2, 4, -6, 4, 2, 1} -the best sum consists of the values in A[0, 6] (the entire array) for a total of 8 For A = {-5, 2, -3, 1, -5, 4, -2) -the best sum consists of the value in A[5] for a total of 4 Note that your algorithm is only required to return the largest possible sum of the benefits, and not the index of the elements in which they were found - this information is only included in the examples as explanation

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!