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]
3 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]3 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
A bowl contains 20 candies; 15 are chocolate and 5 are vanilla. You select 5 at random. What is the probability that all 5 are c
Sindrei [870]

Answer: 0.1937

Explanation:

Given : A bowl contains 20 candies; 15 are chocolate and 5 are vanilla.

If we select 5 candies, then the number of ways to select them is given by permutations.

The number of ways to select 5 candies is given by :-

^{15}P_5=\dfrac{15!}{(15-5)!}=\dfrac{15\times14\times13\times12\times11\times10!}{10!}=360360

The number of ways of selecting any 5 candies out of 20:-

^{20}P_5=\dfrac{20!}{(20-5)!}\\\\=\dfrac{20\times19\times18\times17\times16\times15!}{15!}\\\\=1860480

Now, the probability that all 5 are chocolate :-

=\dfrac{360360}{1860480}=0.193691950464\approx0.1937

Hence, the probability that all 5 are chocolate =0.1937

5 0
4 years ago
Read 2 more answers
Your company has just opened an office in another state and you need the computers to communicate between the offices. What type
galina1969 [7]

Answer:

WAN network

Explanation:

A WAN network is an abbreviation for wide area network. This telecommunication network is mainly used for networking computers. They are not tied to just one location. They can also be called network of networks. It connects several LANs. The lans stand for local area and networks and they are computer networks and devices that are connected to each other within a geographical area.

8 0
3 years ago
You need to find out more about the fdisk utility and the commands associated with it before you set up a new linux system in ad
lutik1710 [3]

The man utility is a console based program that displays manual pages of other utilities, so for fdisk, you would use man -k fdisk to search for fdisk related manuals

7 0
4 years ago
Comparison <br> Cloud computing and parallel processors
V125BC [204]

Anwser is 2/3

Explanation:

7 0
3 years ago
In Excel you insert a comment in a worksheet by using the ____ tab on the Ribbon.
White raven [17]
Review
(I was suprised too)
3 0
4 years ago
Other questions:
  • How do i add a blog to my wordpress site?
    7·1 answer
  • After unit and integration testing are completed, _________ testing ensures that all hardware and software components work toget
    7·1 answer
  • "what are two elements found in an email address?"
    7·1 answer
  • If a drastic change in environmental conditions results in a prolonged drought, how would the total population of ferns be affec
    14·2 answers
  • The word biodegradable on a label doesn't necessarily mean a product is environmentally safe?
    12·1 answer
  • Disk mirroring is a method of storing data that generates extra bits of data from existing data, allowing the system to create a
    14·1 answer
  • There are two circular grounds Ground-A and Ground-B. Ground-A is having diameter of 15 meters and Ground-B is having diameter o
    7·1 answer
  • Which statement describes a biotic factor interacting with the environment?
    5·1 answer
  • PLEASE HELP ME WITH MY UNIT TEST!!!!!!!!!!!!!! I'M STRUGGLING AND I AM ESPECIALLY STUCK ON THIS ONE!!!!!!!!!!!!!!!!!!!!!! FOR BR
    7·1 answer
  • Crisp-DM is an open standard process model that contains stages
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!