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

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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