Question: In JAVA, you will be implementing three very well known sorting algorithms in a class named ArraySorter . Sorting algorithms sort arrays from the smallest

In JAVA, you will be implementing three very well known sorting algorithms in a class named ArraySorter. Sorting algorithms sort arrays from the smallest value to the largest value. Be sure to comment on every method, and any non-elementary code within the method.

Selection Sort: Create a method selectionSort that performs a selection sort of an array of doubles. Selection sort works by selecting the smallest value in the array and swapping with the value at index 0. Then the algorithm moves onto finding the smallest value starting from index 1 and swapping it with the value at index 1. Then the algorithm moves onto finding the smallest value starting from index 2 and swapping it with index 2. This continues until all the values are sorted.

Bubble Sort: Create a method bubbleSort that performs a bubble sort of an array of doubles. The bubble sort algorithm examines all adjacent pairs of elements in the array from the beginning to the end and swaps any two elements that are out of order. Each interchange makes the array more sorted than it was until it is entirely sorted. The algorithm in pseudocode follows:

 for (index = 0; index a[index + 1]) if (a[index] > a[index + 1]) Interchange the values of a[index] and a[index + 1] Insertion Sort: Add a method insertionSort to the class ArraySorter, that performs an insertion sort of an array of doubles. The algorithm is described in detail on Wikipedia. The algorithm in pseudocode something like below: 
 for (index = 1; index  

A good visualization of the algorithm in action can be found at https://visualgo.net/en/sorting

Bonus: The Collatz sequence starting at n is a sequence of integers that starts at n and ending at 1. It generates the next integer in the sequence using the following rules:

In JAVA, you will be implementing three very well known sorting algorithms

where the above function is the next number in the sequence. Using these rules and starting at 10, we get the sequence:

 10 ? 5 ? 16 ? 8 ? 4 ? 2 ? 1

Thus, the Collatz sequence starting at 10, has a length of 7, as there are 7 terms. Find the starting number under one million, which produces that longest chain. Additionally, if you can prove or disprove that for any positive integer (integer in the math sense, not the 32-bit data type) n, the sequence always terminates with 1 (this can be done if commenting if necessary).

TL if n is even f (n) - (3^-i if n is odd

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!