Question

In: Computer Science

In Java: Write two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND...

In Java:

Write two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (Merge Sort OR Quick Sort). If you choose Shell Sort, experiment with different incremental sequences to see how they affect the algorithm's run time efficiency (count the number of comparisons and exchanges). If you choose to implement Radix Sort, answer the following question as well: Can you write a version of Radix Sort for String objects? If yes, explain how. If not, explain why.

Assume that input data is generated randomly and stored in a text file.

You will experiment with your program in two steps:

Step 1: Experimenting with a prototype data (integers from 1 to 10) to ensure that your implementation works correctly and the results match expectations. The results must be reported in a table format (not generated by the program, but collected manually from multiple program runs) in the a Word document as follows:

                 best case         worst case        average case

          char.1...char.N   char.1...char.N   char.1...char.N

alg.1        ...       ...             ...     ...                 ...      ...

alg.2        ...       ...             ...     ...                 ...      ...

  ...  

alg.N      ...       ...              ...     ...                 ...      ...

  

Step 2: Experimenting with large data sets of 2000 elements. The results must be reported in the same table format.

In addition, in the report, explain the empirical results generated by your program comparing them to the known theoretical results paying special attention to any discrepancies which must be clearly explained.

Must submit for grading: the java code, the random text file(s) generated by an independent module (you may need multiple random text files to better characterize the average efficiency of the respective algorithm), AND MOST IMPORTANTLY the report as explained above a Word document.

Solutions

Expert Solution

Insertion short

import java.util.*;
import java.lang.*;
import java.io.*;

class InsertionSort {
  
void sort(int arr[])
{
int n = arr.length;
for (int i = 1; i < n; ++i) {
int key = arr[i];
int j = i - 1;
  
  
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
  
  
static void printArray(int arr[])
{
int n = arr.length;
for (int i = 0; i < n; ++i)
System.out.print(arr[i] + " ");
  
System.out.println();
}
  
  
public static void main(String args[])
{
int arr[] = { 10, 8, 9, 5, 2, 3, 1, 6, 4, 7 };
  
InsertionSort ob = new InsertionSort();
ob.sort(arr);
  
printArray(arr);
}
}

Output:- 1 2 3 4 5 6 7 8 9 10

Selection Short

import java.util.*;
import java.lang.*;
import java.io.*;

class SelectionSort
{
void sort(int arr[])
{
int n = arr.length;
  
  
for (int i = 0; i < n-1; i++)
{

int min_idx = i;
for (int j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
  
  
int temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
}
}
  

void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i<n; ++i)
System.out.print(arr[i]+" ");
System.out.println();
}
  
  
public static void main(String args[])
{
SelectionSort ob = new SelectionSort();
int arr[] = {10, 8, 9, 5, 2, 3, 1, 6, 4, 7};
ob.sort(arr);
System.out.println("Sorted array");
ob.printArray(arr);
}
}

Output:- 1 2 3 4 5 6 7 8 9 10


Related Solutions

(C++)Radix Sort: Write C++ codes for radix sort: use counting sort for decimal digits from the...
(C++)Radix Sort: Write C++ codes for radix sort: use counting sort for decimal digits from the low order to high order. The input array is A = {329, 457, 657, 839, 436, 720, 353}
Import a data set (txt file) then do the sorting algorithm using bubble sort, radix sort,...
Import a data set (txt file) then do the sorting algorithm using bubble sort, radix sort, insertion sort, and merge sort, It must show how long it took and how many movements occurred. Please write codes in C++ Here's data set (should be stored in txt file) 7426 4524 4737 9436 3997 2757 6288 5414 9590 5968 6638 3199 9514 1541 9866 2144 6731 911 2171 6135 6437 912 9417 2662 6606 6349 707 2890 5386 9718 3492 5068 9674...
Import a data set (txt file) then do the sorting algorithm using quick sort, shell sort,...
Import a data set (txt file) then do the sorting algorithm using quick sort, shell sort, and selection sort. It must show how long it took and how many movements occurred. Please write codes in C++ Here's data set (should be stored in txt file) 7426 4524 4737 9436 3997 2757 6288 5414 9590 5968 6638 3199 9514 1541 9866 2144 6731 911 2171 6135 6437 912 9417 2662 6606 6349 707 2890 5386 9718 3492 5068 9674 8578 8323...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort strings of a maximum length of 15. Have an array of strings. Then in the Radix Sort, create an array of LinkedQueue with 95 queues (95 are the printable characters starting with space). Those queues will be used to separate the data then combine them (i.e. bins). Randomly generate 10,000 strings with lengths from 1 to 15 (during the sort and with strings less...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort strings of a maximum length of 15. Have an array of strings. Then in the Radix Sort, create an array of LinkedQueue with 95 queues (95 are the printable characters starting with space). Those queues will be used to separate the data then combine them (i.e. bins). Randomly generate 10,000 strings with lengths from 1 to 15 (during the sort and with strings less...
IN JAVA. Which sorting does in place sorting? Which sort does the minimum swap to order...
IN JAVA. Which sorting does in place sorting? Which sort does the minimum swap to order ascending /desendinf manner?
Hello i need someone to implement for me RADIX SORT IN JAVA for Characters NOT numbers...
Hello i need someone to implement for me RADIX SORT IN JAVA for Characters NOT numbers and i need the code super fast please
Question #1 (Java) - Which sorting does in-place sorting? - Which sort does the minimum swap...
Question #1 (Java) - Which sorting does in-place sorting? - Which sort does the minimum swap to order ascending/descending manner? Note: I just need a short answer to the question no code.
Hello i need someone to implement in JAVA a radix sort algorithm forsorting strings in ascending...
Hello i need someone to implement in JAVA a radix sort algorithm forsorting strings in ascending order. The input to your algorithm should be a (multi)set S = [S1, S2, . . . , Sn] of strings each of which is of length m over the English alphabet [A…Z, a…z]. The output should be the set sorted in ascending lexicographical order. Number of strings is >= 100 and number of characters >= 50 i need the answer fast please
Comparing (Sort Algorithms) Both of the two sorting algorithms will do "sort" on arrays which would...
Comparing (Sort Algorithms) Both of the two sorting algorithms will do "sort" on arrays which would contain x randomly generated integers where the value of x would be 10000, 20000, 40000 and 80000 (inputs). The parts of the program should be followed as..... 1. Set x = 10000, randomly generate x integers. Call qsort function to sort these integers and get the execution time. 2. Randomly generate another x integers. Call your own sorting algorithm and get the execution time....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT