Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

=+ Focus groups with representative publics. Which publics?

Answered: 1 week ago