Write a program that uses the brute-force approach

Assignment Help JAVA Programming
Reference no: EM131453945

Question 1. 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)

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

Question 2. 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 powerset 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 powerset:
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.

Verified Expert

The task was to use brute force to solve 2 problems- 1.To find out the no. of inversions in an array 2.To find out the maximum achievable value by generating all possible subsets in 0-1 knapsack problem

Reference no: EM131453945

Questions Cloud

Determine how you would leverage the support provided : Determine how you would leverage the support provided by the U.S. Small Business Administration in planning and starting your own business.
What are the goals that people share in common motivations : What are the goals that people share in common? Motivations? What recommendations do you have for your organization to enable others to act?
Why were they effective in enabling you to act : Why were they effective in enabling you to act? Finally, create summary message to describe significance of "Enable Others to Act" as it relates to your view.
Determine the value of the process capability index : An automated tube bending operation produces parts with an included angle = 91.2°. The process is in statistical control. and the values of included angle.
Write a program that uses the brute-force approach : Write a program that uses the brute-force approach to count the number of inversions in the array - calculate the total weight and the total value of each subset in the powerset.
What proportion of parts fall outside the tolerance limits : In Problem, the design specification on the part is that the diameter = 30.000 ± 0.150 mm. What proportion of parts fall outside the tolerance limits?
Wide range of emerging business ethics issues : This clip on the HSBC money laundering scandal introduces students to a wide range of emerging business ethics issues, including lying, fraud.
Discuss how a business manager might use cpi statistics : Discuss how a business manager, such as a human resources manager, might use CPI statistics. Analyze the trends in overall inflation over the last five years.
Determine the process capability : A turning process is in statistical control and the output is normally distributed, producing parts with a mean diameter = 30.020 mm and a standard deviation.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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