Question: I need help with the following Java code /** * Simple sorting algorithms' implementations. Note that it is * fine to create private helper methods
I need help with the following Java code
/**
* Simple sorting algorithms' implementations. Note that it is
* fine to create private helper methods inside this class.
* However, you are not allowed to have an instance or class
* variables.
*
* @author
*/
public class SimpleSorts
{
/**
* Sorts entries of array "arr" using recursive selection
* sort algorithm in nondecreasing order. You can assume
* that array won't be null and will have at least 2 elements.
*/
public static void selectionSortRec(int[] arr)
{
}
/**
* Sorts entries of array "arr" using recursive insertion
* sort algorithm in nondecreasing order. You can assume
* that array won't be null and will have at least 2 elements.
*/
public static void insertionSortRec(int[] arr)
{
}
/**
* A bubble sort can sort an array of n entries into nondecreasing order
* by making n-1 passes through the array. On each pass, it compares adjacent
* entries and swaps them if they are out of order. For example, on the first
* pass, it compares the first and second entries, then the second and third
* entries, and so on. At the end of the first pass, the largest entry is in
* its proper position at the end of the array. We say that it has bubbled to
* its correct spot. Each subsequent pass ignores the entries at the end of the
* array, since they are sorted and are larger than any of the remaining entries.
* Thus, each pass makes one fewer comparison than the previous pass.
*
* Here is an example of a bubble sort.
* (Numbers in parentheses represent sorted subarray.)
*
* Original array: 8 2 6 4 9 7 1
* After pass 1 : 2 6 4 8 7 1 (9)
* After pass 2 : 2 4 6 7 1 (8 9)
* After pass 3 : 2 4 6 1 (7 8 9)
* After pass 4 : 2 4 1 (6 7 8 9)
* After pass 5 : 2 1 (4 6 7 8 9)
* After pass 6 : 1 (2 4 6 7 8 9)
*
* Here is the detail of pass 1.
* (Square brackets indicate currently compared entries of array.)
*
* Original array: 8 2 6 4 9 7 1
* Step 1 : [8 2] 6 4 9 7 1 compare 1st and 2nd; swap
* Step 2 : 2 [8 6] 4 9 7 1 compare 2nd and 3rd; swap
* Step 3 : 2 6 [8 4] 9 7 1 compare 3rd and 4th; swap
* Step 4 : 2 6 4 [8 9] 7 1 compare 4th and 5th; no swap
* Step 5 : 2 6 4 8 [9 7] 1 compare 5th and 6th; swap
* Step 6 : 2 6 4 8 7 [9 1] compare 6th and 7th; swap
* Step 7 : 2 6 4 8 7 1 9 steps repeated at next pass.
*
* For more info check: https://en.wikipedia.org/wiki/Bubble_sort
* Note: It is OK to reuse their pseudocode ideas.
*/
/**
* Sorts entries of array "arr" using iterative bubble
* sort algorithm in nondecreasing order. You can assume
* that array won't be null and will have at least 2 elements.
*/
public static void bubbleSortItr(int[] arr)
{
}
/**
* Sorts entries of array "arr" using recursive bubble
* sort algorithm in nondecreasing order. You can assume
* that array won't be null and will have at least 2 elements.
*/
public static void bubbleSortRec(int[] arr)
{
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
