Calculate the total weights and values of each subset

Assignment Help Data Structure & Algorithms
Reference no: EM13315428

Use java to write the programs

1. Write a program that uses the brute-force approach to solve the 0/1 knapsack problem. Suppose there are n items with weights w1, w2, ..., wn and values v1, v2, ..., vn and a knapsack of capacity W. Use the decrease-by-one technique to generate the power set and calculate the total weights and values of each subset, then find the largest value that fits into the knapsack and output that value.

For example: If there are 3 items with the following weights and values:? weight: 8 4 5? value: 20 10 11?and the capacity of the knapsack is 9, your program should then calculate the total weight and the total value of each subset in the power set:? total weight of subset: 0, 8, 4, 12, 5, 13, 9, 17? total value of subset: 0, 20, 10, 30, 11, 31, 21, 41?The largest value that fits into the knapsack: 21

2. Let a[0..n-1] be an array of n distinct integers. A pair (a[i], a[j]) is said to be an inversion if these numbers are out of order, i.e., i<j but a[i] > a[j].

For example: if array a contains the following numbers: ? 9, 8, 4, 5? then the number of inversions is 5. ?(inversions are 9 > 8, 9 > 4, 9 > 5, 8 > 4, 8 > 5)

(a) Write a program that uses the brute-force approach to count the number of inversions in the array.

(b) Write a program that uses the divide-and-conquer technique to count the number of inversion in the array.

 

 

Reference no: EM13315428

Questions Cloud

Cost benefit analysis : Australian Standard for lighting to firstly ensure compliance with the standard and compatibility with current fixtures (T8 linear fluorescent);
Find the frequency of the wave : The distance between two successive minima of a transverse wave is 2.57 m. Five crests of the wave pass a given point along the direction of travel every 12.4 s. Find the frequency of the wave
How many grams of water are in the same solution : How many grams of perchloric acid, HClO4, are contained in 37.6 g of 70.5 wt% aqueous perchloric acid. How many grams of water are in the same solution.
Determine the governing load combination for both moments : A beam that is part of a rigid frame has end moments and mid-span moments for dead, live, and earthquake loads. Determine the governing load combination for both negative and positive moments at the ends and mid-span of the beam.
Calculate the total weights and values of each subset : Use the decrease-by-one technique to generate the power set and calculate the total weights and values of each subset, then find the largest value that fits into the knapsack and output that value.
Determine what is the actual length of the line for steel : A 100ft steel tape measure correctly when supported throughout its length under a tension of 1- lb and at a temperature of 72F.It is used on the field at a tension of 18 lb and supported at the two ends only.
How many watts of power would it take to heat 1 l of water : How many watts of power would it take to heat 1 L of water(weighing 1.0 kg) by 10 degrees Celsius n 1.0 h Assume no heat losses occur, so all of the energy expneded goes into heating the water.
What distance on 5 grade should be laid out with a tape : What distance on 5% grade should be laid out with a tape that measures 30.010 m under field conditions if the horizontal distance is to be 430.00m
What measurements should be laid out to establish a distance : a tape is calibrated and found to measure 100.04ft between the 0- and 100-ft marks. what measurements should be laid out to establish a horizontal distance of 682.25ft

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Design a recursive linear-time algorithm

Design a recursive linear-time algorithm that tests whether a binary tree satisfies the search tree order property at every node.

  Administration plan for the hypothetical situation

Discuss how would you approach a backup and administration plan for hypothetical condition given below. With any network administration systems that should be installed for remote access in event of a network emergency.

  Representation of the newick format

Create the graphical representation of Newick format tree given below. Label each leaf with appropriate sequence identifier, and label each branch with its appropriate length.

  How long would it take to fill the available storage space

How many cells can be in a computer's main memory if each cell's address can be represented by two hexadecimal digits? What if four hexadecimal digits are used? Explain your answer.

  Creating a data flow chart

Create a Data Flow Chart and then make an application that allows a user to enter a stock transaction and determine the stockbroker's commission.

  Design a property database using microsoft access

Database window opens, then type the word Client as the name for this file where the cursor is blinking, then click the create bottom.

  Implementation of graph

Give the two input nodes after the graph has been built from the command prompt.

  Design a representation of display screen

Create a form that lists possible potatoes and toppings in a manner that is easy for counter servers and kitchen crew to scan, and can also be used as input for the inventory reorder system.

  Describe open source and proprietary databases

Describe open source and proprietary databases. What are some drawbacks and benefits of each type of database?

  Creating the table showing decimal value

Assume if the last digit of a 2's complement binary number is 0, then number is even. If the last two digits of a 2's complement binary number are 00

  Algorithm to take input m constraints over n variables

For instance, the constraints x1 = x2, x2 = x3, x3 = x4, and x1 6= x4 cannot be satis fied. Give an efficient algorithm that takes as input m constraints over n variables and decides whether the constraints can be satis fied.

  Identifying the location of rubric objectives

Code Comments are used to identify the location of rubric objectives, Code Formatting is used to raise the readability of the HTML Code.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd