JAVA
Provide a simple code sample of Merge sort
//MergeSortRandomArray.java import java.util.Random; public class MergeSortRandomArray { public static void MergeSort(int arr[], int left, int right) { if (left < right) { int mid = (left+right)/2; MergeSort(arr, left, mid); MergeSort(arr , mid+1, right); merge(arr, left, mid, right); } } public static void merge(int arr[], int left, int mid, int right) { int size1 = mid - left + 1; int size2 = right - mid; int leftArr[] = new int [size1]; int rightArr[] = new int [size2]; for (int i=0; i<size1; ++i) leftArr[i] = arr[left + i]; for (int j=0; j<size2; ++j) rightArr[j] = arr[mid + 1+ j]; int i = 0, j = 0; int k = left; while (i < size1 && j < size2) { if (leftArr[i] <= rightArr[j]) { arr[k] = leftArr[i]; i++; } else { arr[k] = rightArr[j]; j++; } k++; } while (i < size1) { arr[k] = leftArr[i]; i++; k++; } while (j < size2) { arr[k] = rightArr[j]; j++; k++; } } public static void main(String args[]){ int arr[] = new int[5]; Random rand = new Random(); System.out.println("Random array: "); for(int i = 0;i<arr.length;i++){ arr[i] = 1+rand.nextInt(100); System.out.print(arr[i]+" "); } MergeSort(arr,0,arr.length-1); System.out.println("\n\nSorted array: "); for(int i = 0;i<arr.length;i++){ System.out.print(arr[i]+" "); } } }
Implement a parallel version of a sorting algorithm (bubble sort or merge sort). Done in java and a minimum of two threads utilised.
Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....
Java Question:
Code the Merge Sort in such a way that it outputs the number of
comparisons and the number of swaps performed when sorting a random
set of items. Then use it to sort 1000, 5000, 10,000, and 100,000
integers. Tabulate the results and compare it to the number of
comparisons and swaps calculated using the formulas given in Table
8.6.
Table 8.6 Performance of the Quicksort Algorithm Speed Memory Overhead Range Bytes lgorithm Range Effort Comments Binary Tree...
JAVA CODE Provide Java code for a simple class of your choice. Be sure to include at least one constructor, two methods and two fields. The fields should be private. Create a test class to constuct and call the methods of your class. Describe your class and demonstrate your code functions properly.
Illustrate the Merge sort steps (DO NOT Code) to sort the following array. 12 2 100 -4 3 -10 150 10 1
Language is Java. Create an insertion, selection, quick, and merge sort algorithm that sorts 6 9 8 12 3 1 7
How to read an existing file content and then sort them using merge sort into (in java) 1. alphabetical 2. shortest to the longest word
Please help me to solve the problem with java language! An implementation of the Merge Sort algorithm. Modify the algorithm so that it splits the list into 3 sublists (instead of two). Each sublist should contain about n/3 items. The algorithm should sort each sublist recursively and merge the three sorted sublists. The traditional merge sort algorithm has an average and worst-case performance of O(n log2 n). What is the performance of the 3-way Merge Sort algorithm? Merge Sort algorithm...
need help!! java eclipse
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort (pivot - first index) algorithms. a) Compute the CPU processing time for all the algorithms for varying input sizes as follows: N-10, 103, 10, 10, and 106 b) Use a random number generator to generate the inputs. Obtain the inputs from the following input ranges: 1- 10, 1 -10, 1 - 10, 1 12 10 c) Write down your results...
Using Java programming Using System.nanoTime(), compare the performance of bucketsort with the sorting algorithms insertion sort, quicksort, merge sort. Does it really perform faster in practice?