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.

  Explain binary tree by induction

Binary tree is full if all of its vertices have either zero or two children. Let Bn denote number of full binary trees with n vertices. Illustrate by induction (substitution) that Bn is 2 (n) .

  Implement a queue as a circular array

Implement a queue as a circular array as follows: Use two index variables head and tail that contain the index of the next element to be removed and the next element to be added.

  Write a c++ program to find the intersection

Write a C++ program to find the intersection, A set is a collection of distinct entities regarded as a unit, being either individually specified or (more usually) satisfying specified conditions.

  Analyzing certain software properties affects

Describe how the lack of metrics for analyzing certain software properties affects the software engineering discipline.

  Algorithms to insert entry into list and find entry in list

In array is pointer to linked list of nodes each of which starts with corresponding letter. Write algorithms to insert the entry into list and to find entry in the list.

  Write the selection sort algorithm

Write the selection sort algorithm

  Design a method from stack class to reverse the order

Design a method from "Stack" Class to reverse the order of members in a stack. (Stack Order: From 1234 to 4321). No array. (allowed example : push,pop). File Name : Stack.

  Illustrate how b-tree will expand

Illustrate how tree will expand (after inserting each Part#), and what the final tree would like. (b) Repeat item (a), but use a B-tree of order p = 4 instead of a B+-tree.

  Determine algorithm for cs curriculum consists of n courses

Determine an algorithm which works directly with this graph representation, and calculates minimum number of semesters necessary to complete the curriculum.

  Determine effective transfer rate

Assume a network transmits 1024 byte packets having a 128-byte header and a four byte checksum. If a workstation on the network is guaranteed to be able to transmit one packet every x time units,

  Write the implementation of a data structure

Write an implementation of a data structure S that supports the following operations: Insert(S, x): insert the key x into S only if it is not already there.

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