Ask Computer Engineering Expert

Recursion

Overview
This project requires the completion of the following tasks:

- Create an implementation of Merge Sort to recursively sort items
- Create a program to solve the N-Queens problem using recursion
- Create a program to solve the 1/0 Knapsack problem using recursion

Unit Testing
This project requires that for each part you must run the included unit tests to validate and verify the correctness and integrity of your programs, as well as to drive a test-driven development approach. Remember that test-driven development means that test and compilation errors are not necessarily a bad thing; you should use them as an indication of you what code you need to create or fix next.

Start by downloading the interface and unit tests files provided for this assignment and setting-up JUnit for your specific Java development setup. Below are some quick tips for getting started running JUnit tests in several common development setups.

After you turn in your assignment you will be graded using these tests, as well as additional unit tests, so make sure you are thorough in your implementation.

IntelliJ:
• Create a new project and add the interface and test files to the src directory
• Open up one of the test files from within IntelliJ and click on one of the lines underlined with an error
• Press alt+enter (option+enter on mac) and select the option to import the JUnit library into your project
• You should now be able to run each of the tests (right-click the file and choose run), or all of the tests (right-click on the project and choose to run all tests) once you create the classes required for this project

Eclipse
- Create a new project and add the interface and test files to the project src directory (you might need to right-click and refresh the src icon in Eclipse)
- Right-click on the project in the Package Explorer panel, go to Build Path->Add Libraries, and select JUnit
- You should now be able to run the unit tests by right-clicking on the project or test files under Project Explorer, or by going to the run->run as menu

Command Line

For a command line development environment, you will need to perform several steps:

- Download the required JUnit JAR files to your project directory
- Add the JAR files to your project class path when compiling and running
- Create your own driver class (a class with a main method) to run the tests and print out the results

Merge Sort
Merge sort is an algorithm which recursively divides the array into smaller and smaller arrays, and then merges those arrays into each other until the entire set is merged into a sorted order. Remember that as you recursively divide the array you don't need to move the array in memory. You can find a complete description of this algorithm in your textbook as well as online.

1. You must write a MergeSorter class implementing the interface contained in IMergeSorter.java
- Remember to set up Merge Sort's base case. A length 1 or 0 array does not need to be sorted, and returns 0 operations.
- The returned operation count for this sorter is defined as the number of elements that must be merged together during the merge step in each process, summed over all levels of recursion. For example, if you must sort the list [3, 2, 1, 5, 4] you must first sort the lists [3,2] and [1, 5, 4], which also requires you to sort the lists [1] and [5, 4]. Merging [5], [4] into [4,5] takes 2 operations, merging [1], [4, 5] into [1, 4, 5] takes 3 operations. Merging [3],[2] into [2, 3] takes 2 operations. Merging [2, 3], [1, 4, 5] into [1, 2, 3, 4, 5] takes 5 operations. All together this process takes 12 operations.

2. Create a main method which allows you run the MergeSorter for randomly generated numeric arrays of lengths 20,000, 100,000, 500,000, and 2500,000. Record the run times for each call.

- Use the java's System.nanoTime() to record the timing for each call.
- Include a graph of these run times and an analysis of the growth rate in your write-up.

The N-Queens Problem

In chess the Queen is valued as the most powerful piece on the board, capable of moving any number of squares vertically, horizontally, or diagonally. The N-Queens problem proposes trying to place N Queens on an NxN board without any of the queens threatening one another. For a standard chess board N is equal to 8, where you must be able to find a place for 8 queens such that none of them are threatening one another, such as the situation shown in Figure 1.

In this project you are to implement a recursive brute-force solution to this problem, checking every possibility until you find a solution. Place each queen in the first available location and backtrack only when you discover that a particular queen placement is impossible to find a solution for.

This is an example of a depth first search with backtracking, as you explore, in full, the possibilities of each choice in sequence.

3. You must write an NQueensSolver class implementing the interface contained in INQueenSolver.java.

- The interface contains two methods to be complete, on which acts as an entry point, and another which is designed to be called recursively. Normally the recursive call would be private, but we will expose it for testing.

4. Create a main method which allows you run the NQueensSolver for N values from 4 to 12. Run each value of N 100 times, and record the run times for each set of calls.

- Use the java's System.nanoTime() to record the timing for each call.

- Include a graph of these run times and an analysis of the growth rate in your write-up.

The 1/0 Knapsack Problem

The Knapsack problem asks you to pick from a set of items to find the combination with the highest total value under some weight limit. Assume you have a list of items, each of these items with some weight and some value. You also have a knapsack, or backpack, with a specific weight limit. You must determine which items you should take to not exceed the weight limit, while maximizing the value contained in the knapsack.

The recursive solution is to pick an object and then to perform the knapsack problem again with the remaining items and the remaining storage capacity. Once your storage capacity is overloaded you unroll and select the items which lead to the greatest total value. Like the N-Queens problem, this is an example of a depth first search with backtracking.

5. You must write a Knapsack class implementing the interface contained in IKnapsack.java.

- An inner class is defined for you called Item inside of the IKnapsack interface. This models an item that could be placed in the knapsack. An array of these will be passed to your solution method, and you must pick which items to keep, and which to leave.

- You need only return the highest value solution. Should there be multiple even solutions, either is valid.

6. Create a main method which allows you run the Knapsack problem for random items of quantity 10, 15, 20, and 25. Record the run times for each call.

- Each randomly generated item should have a weight and value between 0 and 9. The capacity for each run should be 3 times the number of items.

- Use the java's System.nanoTime() to record the timing for each call.

- Include a graph of these run times and an analysis of the growth rate in your write-up.


Write-up and Submission
- For each part of the project, describe your approach, solutions, describe any difficulties that you encountered, and detail the efficiency of all non-test methods in your code using Big-O notation. Include any requested output and screenshots for each part.

- Add all of your .java files and your write-up document to a .zip or .tar.gz archive and submit it on Bb Learn. Make sure all of your java files are in the root of the zip file, rather than inside additional folders.

- You must write and submit your own code. You must also clearly identify and online or text sources that you used as references, any collaborators with which you discussed the project (or lack thereof), and how the source was beneficial.

Attachment:- Recursion assignment.rar

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92023302
  • Price:- $140

Guranteed 48 Hours Delivery, In Price:- $140

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As