Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Matlab Don't use sort function Given weights = randi(500,1,randi(20)) capacity = 1000; You are given an array, weights, that contains the weights of

Please use Matlab
Don't use sort function
Given
weights = randi(500,1,randi(20))
capacity = 1000; image text in transcribed
You are given an array, weights, that contains the weights of some cargo items in pounds. You want to load a truck with items from the list, up to its capacity. The truck has a maximum capacity of 1,000 pounds. For this problem use a "greedy" algorithm. That is, always load the heaviest item that will still fit on the truck. Keep loading until the remaining capcity of the truck is less than any of the remaining cargo items. For example, if the weights were 400, 250, 700, 100, 60), you would load the 700-pound item, then the 250-pound item. The remaining items would be too heavy to fit on the truck. This problem differs from the previous one in that the weights are NOT sorted, and you may not use the sort() function. The weights will be generated randomly, so you cannot hard-code the answer - you must write a general algorithm to do it. Once the loading is complete, print a message indicating how many pounds of cargo were loaded onto the truck. NOTE: To satisfy the auto-grader, update the variable capacity so that it contains the remaining capacity of the truck. For example, if 943 pounds of cargo are loaded, capacity should be 57

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

Step: 3

blur-text-image

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions