1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
guapka [62]
2 years ago
10

1- Design a brute-force algorithm for solving the problem below (provide pseudocode): You have a large container with storage si

ze: W lb. You have many Items (n) where each item weight is: wi. the algorithm you design should find the subset of items with the largest weight not exceeding W (Container storage capacity)
2- Submit a simple program in Java that implements your algorithm with an example test run.
Computers and Technology
1 answer:
sladkih [1.3K]2 years ago
3 0

Answer:

Pseudocode is as follows:

// below is a function that takes two parameters:1. An array of items 2. An integer for weight W

// it returns an array of selected items which satisfy the given condition of sum <= max sum.

function findSubset( array items[], integer W)

{

initialize:

maxSum = 0;

ansArray = [];

// take each "item" from array to create all possible combinations of arrays by comparing with "W" and // "maxSum"

start the loop:

// include item in the ansArray[]

ansArray.push(item);

// remove the item from the items[]

items.pop(item);

ansArray.push(item1);

start the while loop(sum(ansArray[]) <= W):

// exclude the element already included and start including till

if (sum(ansArray[]) > maxSum)

// if true then include item in ansArray[]

ansArray.push(item);

// update the maxSum

maxSum = sum(ansArray[items]);

else

// move to next element

continue;

end the loop;

// again make the item[] same by pushing the popped element

items.push(item);

end the loop;

return the ansArray[]

}

Explanation:

You can find example to implement the algorithm.

You might be interested in
Which of these are correctly formatted Python dictionaries? Check all that apply. dict = {‘Name’: ‘Matthew’, ‘Age’: 14, ‘School’
Advocard [28]

Answer:

A. dict = {‘Name’: ‘Matthew’, ‘Age’: 14, ‘School’: ‘ABC School’}

Explanation:

Since <em>python does not use type when declaring a variable</em>, you must make sure you make your variables correctly or else it won't compile correctly. Lists use braces[]; Strings use quotes, "" or ''; Integers are just declared with a number(s); Dictionaries use brackets{} and inside are <u>attributes of something</u>. For instance, you can use dictionaries to describe ages, {'"Bryan": 6, "Alex": 13, etc.} <u>Sort of like a json file</u>. Dictionaries also tend to use <u>uppercase letters</u> when describing something. The only answer that has all the attributes correct is A. dict = {‘Name’: ‘Matthew’, ‘Age’: 14, ‘School’: ‘ABC School’}

hope i helped :D

7 0
3 years ago
Read 2 more answers
Suggest me a website or any channel for learning coding.
gulaghasi [49]

Answer: Codeacademy. One of the most popular free places to learn coding is Codeacademy.

Explanation:

6 0
2 years ago
You have just installed the microsoft windows 7 operating system on your pc. which web browser is bundled with windows 7 and is
kirill [66]
The web browser that is automatically installed with windows 7 is Internet Explorer.

Hope this helps.
6 0
3 years ago
Secondary​ shots, used for visual interest and to smooth over​ transitions, are called​ _________ material.
kvasek [131]

Video source material that's used to fill holes in the timeline where synchronized video is not included, or as a source of supplemented footage to accompany a video sound bite, visually supports what is happening on-screen. Video footage that supports the spoken narrative but that is not synchronized with it (e.g. an establishing shot of a scene that appears on screen while the narrator or reporter's voice introduces the story)

6 0
3 years ago
Read 2 more answers
What is the term for a piece of data that is to be operated upon or manipulated in some manner?
notka56 [123]
Data Manipulation 
Is there any choices?

8 0
2 years ago
Other questions:
  • Mateo could not find the undo command or shortcut. He should _____.
    15·2 answers
  • Which feature is an interface between the user and the file system of a computer?
    6·2 answers
  • 8. A pattern of being late for work or for appointments is usually
    12·1 answer
  • What is the digital revolution and how did it change society? What are the benefits of digital media?
    8·1 answer
  • A company has its branches spread over five places in a state. It has become difficult for employees to transfer information and
    7·1 answer
  • Ali is in the hospital about to undergo a brain-imaging process that involves taking many x-rays from different angles aided by
    9·1 answer
  • 1)Write the command that moves the file data1 into the directory testdata:
    9·1 answer
  • User Interface Design ensures that the interface has elements that are easy to ________________. (Choose all that apply)
    10·2 answers
  • What is contained in the Open Files section of Shared Folders? ​
    13·1 answer
  • Basil was reading about a new attack that forces the system to abandon a higher cryptographic security mode of operation and ins
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!