---Using Java to solve---
Write the code for three sort algorithms. Sort an array of Integers, strings and an array of Cars using each technique. At least seven items in each case.
/* Insertion Sort on Array of Integers*/
class InsertionSort
{
/*Function to sort array using insertion sort*/
void sort(int arr[])
{
int n = arr.length;
for (int i=1; i<n; ++i)
{
int key = arr[i];
int j = i-1;
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
while (j>=0 && arr[j] > key)
{
arr[j+1] = arr[j];
j = j-1;
}
arr[j+1] = key;
}
}
/* A utility function to print array of size n*/
static void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i<n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}
// Driver method
public static void main(String args[])
{
int arr[] = {12, 11, 13, 5, 6};
InsertionSort ob = new InsertionSort();
ob.sort(arr);
printArray(arr);
}
}
/*Bubble Sort on String */
import java.util.*;
public class BubbleSort {
public static void main(String[] args) {
String list[]={"Artichoke" , "Apple" , "Cherry" , "Banana","Guava","Mango","Pineapple"};
BubbleSort(list);
for(int i=0; i<list.length; i++)
{
System.out.println(list[i]);
}
}// End of Main
private static void BubbleSort(String[] array) {
String temp;
// Begin For loop
for(int i=0; i<array.length; i++) {
//Open For loop
for(int j=0; j<array.length-1-i; j++) {
//Open If Statement Compare and sort strings
if(array[j].compareTo(array[j+1])>0) {
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}//End of If Statement
}//End of For Loop
}//End of For Loop
}//End of Private Class BubbleSort
}// End of Public class Bub
/*Sorting Cars using Selection Sort*/
import java.util.Scanner; class program1 { public static void main(String[] args) { int n; String temp; String names[] = {"Dodge" , "Porsche" , "Bugatti" , "Lamborghini","Chevrolet","Ferrari","Shelby"}; for (int i = 0; i < names.length; i++) { for (int j = i + 1; j < names.length; j++) { if (names[i].compareTo(names[j])>0) /*comapareTo method is used to compare between the two names in the list */ { temp = names[i]; names[i] = names[j]; names[j] = temp; } } } for (int i = 0; i < names.length - 1; i++) { System.out.print(names[i] + ","); } System.out.print(names[names.length - 1]); } }
---Using Java to solve--- Write the code for three sort algorithms. Sort an array of Integers,...
q: Write a java code to Test the heap sort algorithm Test the algorithms on arrays of size: .100,000 , 90,000 ,80,000 ,70,000 ,60,000 ,50,000 ,40,000 ,30,000 ,20,000 ,10,000 Plot the execution time vs array size. without using excel
Java - Data Structures Q. Implement one of the sorts ( Selection Sort / Insertion Sort / Shell Sort / Merge Sort ) described in Chapters 8 and 9 . Input is an array with at least 10 items. The items can be of any type (Suggested types are integers—denoting how many patrons visited the library in the last three weeks or strings—denoting the names of books returned today). Print the original data. Print the sorted data.
Implement and compare sorting algorithms. The task is to sort a list of integers using 5 sorting algorithms: selection sort insertion sort merge sort heap sort quicksort Your program should include 5 separate sorting methods, though it is fine for them to call some common methods (like "swap") if needed. Each sorting method should also count the number of comparison operations and assignment operations on the array elements during the sorting process. In the main program, two types of array...
Need a quick solution to this in Java! OPTION 2: RADIX SORT TESTING Write a version of Radix Sort to sort an ArrayList or array of ints / Integers that you will place in a file. The integers should all be four digits long. Run the algorithm on at least 3 different files, of different sizes (i.e., each file should have a different number of integers) and have it print the results. The minimum file size should be 20 integers....
Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order (from smallest to largest). You can either get the array as input or hardcode it inside your program.
Implement the following sorting algorithms using Java: a. Heap Sort. b. Quick Sort. c. Radix Sort. Verify the correctness of each implemented algorithm by sorting the following array: 10, 5, 60, 53, 45, 3, 25,37,39,48
For each of the following two sorting algorithms, describe its operation in detail, using diagrams, Java code, and/or pseudocode as you feel are appropriate As part of your answer, for each one, demonstrate how it operates by showing all passes over the following array of integers: [3, 7,1, 11,5,2,8,4,9 (i) Shell Sort
This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort Heap Sort You have access to the implementation of all of these sorting algorithms, and you may use what is provided in your text directly. Be sure to cite the source of these implementations in the header of your program. Please maintain the property that these sorting algorithms sort arrays in ascending order. For this homework, you will write a...
In C++ language, implement a class that can sort an array of numbers using all three algorithms we have seen in this course, but each method updates a “counter” value every time it accesses the array. Have it print this at the end of the sorting process. Store the array values in an “original” array so you don’t have to re-type it for different sorts (since each sort alters the array), and have the sort modify a copy. Note: IF...