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
An oscilloscope display grid or scale is called?
zaharov [31]

Answer:

An oscilloscope display grid or scale is called a graticule.

Explanation:

5 0
3 years ago
Read 2 more answers
2. The value of the difference between the return on one investment and the return on an alternative
cricket20 [7]
B is correct answer hope that helps
5 0
4 years ago
Read 2 more answers
Use differentials to estimate the amount of metal in a closed cylindrical can that is 30 cm high and 6 cm in diameter if the met
PilotLPTM [1.2K]

Answer:

dV=113.55 \ cm^3

Explanation:

<u>The Differential of Multivariable Functions</u>

Given a multivariable function V(r,h), the total differential of V is computed by

dV=\displaystyle \frac{\partial V}{\partial  r} dr+\frac{\partial V}{\partial  h} dh

The volume of a cylinder of radius r and height h is

V=\pi\cdot r^2\cdot h

Let's compute the partial derivatives

\frac{\partial V}{\partial  r}=2\pi rh

\displaystyle \frac{\partial V}{\partial  h}=\pi r^2

The total differential is

dV=(2\pi rh)dr+(\pi r^2)dh

The differential dr is approximated to \Delta r and the differential dh is approximated to \Delta h. We can see the increment of radius is the thick of the metal in the sides, and the increment of the height is the thick of the metal in the top and bottom. Thus dr=0.05 cm, dr=0.2 cm

dV=(2\pi \cdot 3\ cm\cdot 30\ cm)0.2\ cm+(\pi\ (3\ cm)^2)0.05\ cm

dV=113.55 \ cm^3

5 0
3 years ago
14. A digital computer has a memory unit with 32 bits per word. The instruction set consists of 110 different operations. All in
Fofino [41]

Answer:

7 bits

Explanation:

Given

Instruction Set = 110 operation

Memory unit = 32 bits per word.

We get the required bits by using the following formula

2^n = 110

But 110 is not a factor of 2.

So, we pick the nearest decimal number greater than 110 that is a power of 2.

The number is 128

2^n = 110 becomes

2^n = 128

2^n = 2^7 ---- 2 cancels out

So,

n = 7

Hence, the required number of bits needed for the opcode is 7 bits

5 0
3 years ago
The current though a capacitor cannot change instantaneously.
malfutka [58]

Answer: The answer is (b) False

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is the thermal efficiency of a gas power cycle using thermal energy reservoirs at 627°C and 60°C? The thermal efficiency is
    12·1 answer
  • A hollow steel tube with an inside diameter of 100 mm must carry a tensile load of 400 kN. Determine the outside diameter of the
    12·2 answers
  • If a plus sight of 12.03 ft is taken on BM A, elevation 312.547 ft, and a minus sight of 5.43 ft is read on point X, calculate t
    13·1 answer
  • Using the AASHTO procedure, determine the thickness required for a base and a surface layer over existing subgrade. The structur
    12·1 answer
  • Multiple Choice
    5·1 answer
  • Is it possible to create any digital logic circuit just using AND/OR/NOT gates?
    14·1 answer
  • 7. A single-pole GFCI breaker is rated at
    9·1 answer
  • Inductors in series obey the same formula as resistors in series. That is, if you connect two inductors are in series, the equiv
    12·1 answer
  • Water exerts little pressure on a building so it has no implications on foundation design.
    14·1 answer
  • true or false: the types of building materials that’s should be used in a project does not constitute a conditional for projects
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!