Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started