Question: Create a new project called YourlastnameLab 6 . A text editor window should pop up , showing the content of the java main class file
Create a new project called YourlastnameLab A text editor window should pop up showing the content of the java main class file titled YourlastnameLabjava. The main class file is automatically created when you create a new project and displays template source code from NetBeans. In the main function of your main class, remove the line that prints Hello World to the output screen and save the file Write a recursive method to display the contents of an array.a Write a private static void method called displayArray that takes an array of ints and an int representing the index of the first item to display and does the following: If the index is equal to the length of the array, display a newline. Otherwise, display the item at the index in a field three characters wide youll see why later and perform a recursive call to display the remaining items.b Write an overloaded public static void method also called displayArray that takes an array of ints and calls the private displayArray to display the contents of the array starting at index c Write code in the main method to test displayArray.d Compile and run the program to see if it works. The output of this test code might look something like this: Displaying array with items Write a recursive method to display a string in reverse.e Write a public static void method called displayReverse that takes a String as an argument and does the following: If the length of the string is do nothing. Otherwise pass a substring of the string without the first character to a recursive call, then display the first character.f Write code in the main method to test the displayReverse method.g Compile and run the program to see if it works. The output of this test code might look something like this: Calling displayReverseHello World!"dlroW olleH Write a recursive method to calculate the factorial of a number.h The factorial of a positive integer written as is the product of all integers from to can be calculated recursively using the following formulas:i Write a public static void int method called factorial that takes an int as an argument and does the following. If the number is less then or equal to return Otherwise return the product of and You may want to make the return type a long, as factorials can get very large.j Write code in your main method to test the factorial method.k Compile and run the program to see if it works. The output of this test code might look something like this: Calling factorialresult: Calling factorialresult: Write a recursive method to perform a binary search.l Write a private static void method called displayArrayIndexes that takes an array of ints and four int arguments representing current, first, middle, and last indexes and does the following: Use the same base case that you used in displayArray. The recursive case is similar, but instead of displaying the item at the current index, display a string that contains: An F if the current index is equal to the first index. An M if the current index is equal to the middle index. An L if the current index is equal to the last index. Note that the current index may be equal to any combination of the three other indexes. You may want to test this out before moving to the next step.m Write a private static void int method called binarySearch that takes an array of ints, an int representing an item to search for, and two additional ints representing first and last indexes and does the following: Perform a recursive binary search that returns the location of the item or if the item is not found. After calculating the middle index, call displayArray to display the array, then call displayArrayIndexes to display the three array indexes.n Write an overloaded public static void int method also called binarySearch that takes an array of ints, and an int representing an item to search for, and calls the private binarySearch method to search the entire array.o Write code in the main method to test binarySearch.p Compile and run the program to see if it works. The output of this test code might look something like this: Calling binarySearch to search for F M L F M L FM L FML result: Write a recursive method to sort an array using the quicksort algorithm.q The quicksort performs the following operations given a range of at least two array items: Choose an item to be the pivot. Partition the array into items less than or equal to the pivot and items greater than the pivot. Recursively sort the first partition. Recursively sort the second partition.r Write a private void method called swap that takes an array of ints and two indexes and swaps the items at the two indexes.s Write a private method called partition that takes an array of ints, an int representing a pivot value, and two ints representing first and last indexes and does the following: Initialize an index variable i to start at the first index. Initialize another index variable j to start at the last index. While i is less than j do the following: Increment i until the array element at index i is greater than the pivot value or i has reached the last index. Decrement j until the array element at index j is less than the pivot value or j has reached the first index. If i is still less than j swap the items at the two locations. At this point, all of the items less then the pivot item should come before all of the items greater than the pivot. Return the j index, which should now point to the last item that is less than or equal to the pivot. You might want to test this out before moving to the next step.t Write a private void method called quicksort that takes an array of ints, and two int representing first and last indexes and does the following: If the first index is greater than or equal to the last index, do nothing. Otherwise do the following: Call partition to partition the range of the array from the first index to the last index using the first item as a pivot. Call swap to swap the item at the first index with the item at the pivot index returned by partition. Use a recursive call to sort the range from the first index to the index right before the pivot index. Use a recursive call to sort the range from the index right after the pivot index to the last index.u Write a overloaded pubic static void method, also called quicksort that takes an array of ints and uses the private quicksort method to sort the entire array.v Write code in your main method to test quicksort.w Compile and run the program to see if it works. The output of this test code might look something like this: Array before calling quicksortArray after calling quicksort
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
