Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recursion6_UML public class MyRecursion6{ //********************************************** //1. Declarations //********************************************** private static Integer [] oddList; private static Integer [] evenList; private static Integer [] randomOddList; private static

image text in transcribed

Recursion6_UMLimage text in transcribed

public class MyRecursion6{ //********************************************** //1. Declarations //********************************************** private static Integer [] oddList; private static Integer [] evenList; private static Integer [] randomOddList; private static Integer [] randomEvenList; private static Integer [] selectionSortOddList; private static Integer [] quickSortOddList; private static int selectionSortCount; private static int quickSortCount; private static int successfulLinearSearchCount; private static int unsuccessfulLinearSearchCount; private static int successfulBinarySearchCount; private static int unsuccessfulBinarySearchCount;

//private static int binarySearchCount; //successfulBinarySearchCount private static int size;

//********************************************** //2. main: reading size as a command-line argument // declare the needed arrays //********************************************** public static void main (String [] args){ size = Integer.parseInt(args[0]); oddList = new Integer[size]; evenList = new Integer[size]; randomOddList = new Integer[size]; randomEvenList = new Integer[size]; selectionSortOddList = new Integer[size]; quickSortOddList = new Integer[size];

//3. Create an object of Recursion6 class Recursion6 r = new Recursion6(); //4. populate oddList with values 1,3,5,... // oddList is sorted r.populateOddList(oddList); // r.displayList(oddList); //5. populate evenList with values 0,2,4,... // evenList is sorted r.populateEvenList(evenList); //r.displayList(evenList); //6. clone oddList into randomOddList // randomOddList is still sorted randomOddList = r.cloneList(oddList); //r.displayList(randomOddList); //7. clone evenList into randomOddList // randomEvenList is still sorted randomEvenList = r.cloneList(evenList); //r.displayList(randomEvenList); //8. shuffle randomOddList // randomOddList is random now r.shuffleList(randomOddList); //r.displayList(randomOddList); //9. shuffle randomOddList // randomEvenList is random now r.shuffleList(randomEvenList); //r.displayList(randomEvenList); //10. Clone randomOddList into selectionSortOddList // Use selection sort to sort selectionSortOddList selectionSortOddList = r.cloneList(randomOddList); selectionSortCount = r.selectionSort(selectionSortOddList); //r.displayList(selectionSortOddList); //11. Clone randomOddList into selectionSortOddList // Use quick sort to sort quickSortOddList quickSortOddList = r.cloneList(randomOddList); quickSortCount = r.quickSort(quickSortOddList); //r.displayList(randomOddList); //r.displayList(quickSortOddList);

//12. Use linearSearch to search for all values in OddList in randomOddList successfulLinearSearchCount = r.linearSearch(randomOddList, oddList); unsuccessfulLinearSearchCount = r.linearSearch(randomOddList, evenList);

//13. Use binarySearch to search for all values in randomOddList in OddList successfulBinarySearchCount = r.recursiveBinarySearch(randomOddList, oddList); unsuccessfulBinarySearchCount = r.recursiveBinarySearch(randomOddList, evenList); //14. Use recursiveMax to find and return the largest value in array r.shuffleList(randomOddList); //r.displayList(randomOddList); System.out.printf (" \t1.\t%-40s%10d","Largest value is:",r.recursiveMax(randomOddList));

//15. Use recursiveBackward display array in backward order System.out.printf (" \t2.\t%-40s \t\t","List in Backward order:"); r.recursiveBackward(randomOddList);

//14. Display counts System.out.printf (" \t3.\t%-40s%10d","List size:",size); System.out.printf (" \t4.\t%-40s%10d","Selection Sort Count:",selectionSortCount); System.out.printf (" \t5.\t%-40s%10d","Quick Sort Count:",quickSortCount); System.out.printf (" \t6.\t%-40s%10.2f","Successful Linear Search Average:",(double)successfulLinearSearchCount/size); System.out.printf (" \t7.\t%-40s%10.2f","UnSuccessful Linear Search Average:",(double)unsuccessfulLinearSearchCount/size); System.out.printf (" \t8.\t%-40s%10.2f","Successful Binary Search Average:",(double)successfulBinarySearchCount/size); System.out.printf (" \t9.\t%-40s%10.2f ","UnSuccessful Binary Search Average:",(double)unsuccessfulBinarySearchCount/size); } }

I. Objectives: a. Command-line arguments b. Arrays c. clone0 method d. Collections shuffle method e. Implementing and evaluating selection sort f. Implementing and evaluating quick sort g. Implementing and evaluating linear searchv h. Implementing and evaluating binary search i. Finding the Largest Value in an Array. j. Printing an Array Backward- II.Write a program named Recursion6 as specified in the attached UML diagram. Recursion6 should be used with the attached driver. Do not modify the driver.+ III Each team submits a single copy of project zipped into a single file, additionally, each team member submits her/his project report. Each team should submit the following items:- a. MyRecursion6.java (driver). b. Recursion6.java- c. SampleRun6- . Note: Make sure that your program is well documented, and readable. . The output is well labeled and aligned IV. Sample input/output runs with size 20 33 21 25 39 35231 27+ 29 3113 17377 19 5 Largest value is 39 2.List in Backward order 1519 35 19 7 37 17 13 31 29 27 11 23 35 39 25 21 33 List size Selection Sort Count: 20- 190v 5. Quick Sort Count: 68 10.50 20.00 Successful Linear Search Average 7. UnSuccessful Linear Search Average 3.70 5.50 Successful Binary Search Average 9. UnSuccessful Binary Search Average Recursion6 To be used to count comparisons No-argument constructor+ Populate the array with even values starting with 0 Populate the array with odd values starting with 1+ Clone list and return its clonew + counts:int +Recursion6+ +populateEvenistlist: Integer[l):void +populateOddist(list: Integer[l): void +cloneList(list: Integer[l):Integerl- +shuffleList(listnteger ):void +SelectionSort(list: Integerl):int Shuffle the list. You may use Collections shuffle Use selection sort to sort the list. count and return the number of comparisons+ +quickSort(list: Integerl):int Use quick sort to sort the list. count and return the number of comparisons -quicksort(list: Integerfl, firstint, last: int):void- l Private method to help +' -partition(list:Integerll, first:int, last:int):int- Private helper method to find and return the partition index +linearSearch(list1:Integer[I,list2:Integer[l):intSearches for all numbers in Ist1 in list2 and counts the number of comparisons made. When done, returns the number of comparisons. trecursiveBinarySearch list1:Integer[l, list2:Integerl): int- Implement recursiveBinarySearch. List2 is sorted Search for all values in list1 against list2. Count number of comparisons. + -recursiveBinarySearch(list:Integerl, kev:Integer, P low:int, high:int):voide Private method that is invoked from the public recursiveBinarySearch method. Increments number of comparisons. +displayist(listlntegerl:void +recursiveMax(list: Integer):Integer+ trecursiveBackward(listIntegerl);voide Receives and array. It displays its values 8 per line. Receives and array and returns the largest Receives and array and prints its values in backward order. I. Objectives: a. Command-line arguments b. Arrays c. clone0 method d. Collections shuffle method e. Implementing and evaluating selection sort f. Implementing and evaluating quick sort g. Implementing and evaluating linear searchv h. Implementing and evaluating binary search i. Finding the Largest Value in an Array. j. Printing an Array Backward- II.Write a program named Recursion6 as specified in the attached UML diagram. Recursion6 should be used with the attached driver. Do not modify the driver.+ III Each team submits a single copy of project zipped into a single file, additionally, each team member submits her/his project report. Each team should submit the following items:- a. MyRecursion6.java (driver). b. Recursion6.java- c. SampleRun6- . Note: Make sure that your program is well documented, and readable. . The output is well labeled and aligned IV. Sample input/output runs with size 20 33 21 25 39 35231 27+ 29 3113 17377 19 5 Largest value is 39 2.List in Backward order 1519 35 19 7 37 17 13 31 29 27 11 23 35 39 25 21 33 List size Selection Sort Count: 20- 190v 5. Quick Sort Count: 68 10.50 20.00 Successful Linear Search Average 7. UnSuccessful Linear Search Average 3.70 5.50 Successful Binary Search Average 9. UnSuccessful Binary Search Average Recursion6 To be used to count comparisons No-argument constructor+ Populate the array with even values starting with 0 Populate the array with odd values starting with 1+ Clone list and return its clonew + counts:int +Recursion6+ +populateEvenistlist: Integer[l):void +populateOddist(list: Integer[l): void +cloneList(list: Integer[l):Integerl- +shuffleList(listnteger ):void +SelectionSort(list: Integerl):int Shuffle the list. You may use Collections shuffle Use selection sort to sort the list. count and return the number of comparisons+ +quickSort(list: Integerl):int Use quick sort to sort the list. count and return the number of comparisons -quicksort(list: Integerfl, firstint, last: int):void- l Private method to help +' -partition(list:Integerll, first:int, last:int):int- Private helper method to find and return the partition index +linearSearch(list1:Integer[I,list2:Integer[l):intSearches for all numbers in Ist1 in list2 and counts the number of comparisons made. When done, returns the number of comparisons. trecursiveBinarySearch list1:Integer[l, list2:Integerl): int- Implement recursiveBinarySearch. List2 is sorted Search for all values in list1 against list2. Count number of comparisons. + -recursiveBinarySearch(list:Integerl, kev:Integer, P low:int, high:int):voide Private method that is invoked from the public recursiveBinarySearch method. Increments number of comparisons. +displayist(listlntegerl:void +recursiveMax(list: Integer):Integer+ trecursiveBackward(listIntegerl);voide Receives and array. It displays its values 8 per line. Receives and array and returns the largest Receives and array and prints its values in backward order

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions