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
levacccp [35]
3 years ago
6

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 any language you prefer that implement your algorithm with an example test run.
Engineering
1 answer:
Natalija [7]3 years ago
7 0

Answer: Provided in the explanation section

Explanation:

1. Algorithm:

Input: Container storage capacity-W, Weights of n items w[n]. w[i] represents the weight of the nth item.

Output: a subset of items with the largest weight not exceeding W.

Algorithm: To find the subset of items with the largest weight not exceeding W, we can use a recursive algorithm. We define Solve(W, i) as a solution to the problem with weight W and i items, then our recurrence can be written as:

Solve(W,i) = max(Solve(W,i-1) , w[i] + Solve(W-w[i],i-1)). We get this relation because for every item (ith) item we have two options, either we include it in our container or we do not include it.

When we do not include ith items in the container, then we have to solve the problem for remaining items with the same weight so we get Solve(W,i-1).

When we include ith items in the container, then we have to solve the problem for remaining items with the reduced weight so we get w[i] + Solve(W-w[i],i-1). Here we have added w[i] because we have included ith item in our container.

2.  Using C++ Implementation:

#include<bits/stdc++.h>

using namespace std;

// this funtion finds the subset of items with the largest weight not exceeding W (Container storage capacity) and returns maximum possible weight of items

int solve(int w[],int W,int i,int n)

{

  //   if our weight has become zero or we have reached at the end of items then we simply return 0

  if(W==0 || i==n)

      return 0;

  else

  {

  // if weight of ith item is more than W then we have only one case, we have to ingore the ith item      

      if(w[i]>W)

      {

          return solve(w,W,i+1,n);

      }

      else

      {

          //now we have two cases, we can incude ith item or we can ignore ith item

         

          //case-1

          int include_ith_item = w[i]+solve(w,W-w[i],i+1,n);

          //case-2

          int exclude_ith_item = solve(w,W,i+1,n);

         

          //and we return the maximum of these two cases

          if(include_ith_item>exclude_ith_item)

          {

              return include_ith_item;

          }

          else

          {

              return exclude_ith_item;

          }

      }

  }

}

int main()

{

  //   some example data to test our funtion

  int w[5] = {10,12,13,9,43};

  int n=5;

  int W = 50;

  set <int> ::iterator it;

  cout<<"The largest possible weight of subsets is: "<<solve(w,W,0,5);

}

cheers i hope this helped !!!

You might be interested in
A thermoelectric refrigerator is powered by a 16-V power supply that draws 2.9 A of current. If the refrigerator cools down 3.1
Viktor [21]

Answer:

COP = 0.090

Explanation:

The general formula for COP is:

COP = Desired Output/Required Input

Here,

Desired Output = Heat removed from water while cooling

Desired Output = (Specific Heat of Water)(Mass of Water)(Change in Temperature)/Time

Desired Output = [(4180 J/kg.k)(3.1 kg)(25 - 11)k]/[(12 hr)(3600 sec/hr)]

Desired Output = 4.199 W

And the required input can be given as electrical power:

Required Input = Electrical Power = (Current)(Voltage)

Required Input = (2.9 A)(16 V) = 46.4 W

Therefore:

COP = 4.199 W/46.4 W

<u>COP = 0.090</u>

8 0
3 years ago
How do you identify all sensors, functions, and where we can use them?
Alex17521 [72]

Sensor/Detectors/Transducers are electrical, opto-electrical, or electronic devices composed of specialty electronics or otherwise sensitive materials, for determining if there is a presence of a particular entity or function. Many vehicles including cars, trains, buses etc. all use sensors to monitor oil temperature and pressure, throttle and steering systems and so many more aspects.

7 0
3 years ago
Which basic principle influences how all HVACR systems work?
bezimeni [28]

Answer:

B) An increase in pressure can lower the boiling point of a liquid and change the temperature at which it turns to a gas.

Explanation:

B) An increase in pressure can lower the boiling point of a liquid and change the temperature at which it turns to a gas.

6 0
3 years ago
To assist in completing this question, you may reference the Animated Technique Video - MALDI-TOF Mass Spectroscopy. Complete th
a_sh-v [17]

Complete Question

The complete question is shown on the first uploaded image.

Answer:

The answer is shown on the second uploaded image

Explanation:

The explanation is also shown on the second uploaded image

3 0
4 years ago
How do you check battery state of charge with a voltmeter
cupoosta [38]

Answer:

Depends on the battery and the current type.

Is it AC or DC?

Explanation:

Could you mark as brainiest.

I need it for my account

Thank you! :)

8 0
3 years ago
Other questions:
  • Mike is involved in developing the model building codes that various states and local authorities in the United States adopt. He
    6·1 answer
  • A liquid-liquid extraction process consists of two units, a mixer and a separator. One inlet stream to the mixer consists of two
    7·1 answer
  • What entrepreneurial activities do you know?are you capable of doing entrepreneurial activities
    15·1 answer
  • Air is used as the working fluid in a simple ideal Brayton cycle that has a pressure ratio of 12, a compressor inlet temperature
    13·1 answer
  • Which of the following are all desirable properties of a hydraulic fluid? a. good heat transfer capability, low viscosity, high
    5·1 answer
  • In the 5 Code of Federal Regulations (C.F.R.), it is recommended that an individual has security awareness training before s/he
    8·2 answers
  • When an output gear is larger than the input gear the greater ratio is greater than 1 T or F​
    9·1 answer
  • Materials to be used to build a watch tower​
    9·1 answer
  • Which of the following is described as a way engineers can test and investigate how things should be under certain circumstances
    8·1 answer
  • Do better then me......................................
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!