provided code:
import java.util.Comparator;
import java.util.List;
import java.util.LinkedList;
import java.util.Queue;
/**
* Your implementation of various divide & conquer sorting algorithms.
*/
public class Sorting {
/**
* Implement merge sort.
*
* It should be:
* out-of-place
* stable
* not adaptive
*
* Have a worst case running time of: O(n log n)
* And a best case running time of: O(n log n)
*
* You can create more arrays to run merge sort, but at the end, everything
* should be merged back into the original T[] which was passed in.
*
* When splitting the array, if there is an odd number of elements, put the
* extra data on the right side.
*
* Hint: You may need to create a helper method that merges two arrays
* back into the original T[] array. If two data are equal when merging,
* think about which subarray you should pull from first.
*
* You may assume that the passed in array and comparator are both valid
* and will not be null.
*
* @param <T> Data type to sort.
* @param arr The array to be sorted.
* @param comparator The Comparator used to compare the data in arr.
*/
public static <T> void mergeSort(T[] arr, Comparator<T> comparator) {
// WRITE YOUR CODE HERE (DO NOT MODIFY METHOD HEADER)!
}
/**
* Implement LSD (least significant digit) radix sort.
*
* It should be:
* out-of-place
* stable
* not adaptive
*
* Have a worst case running time of: O(kn)
* And a best case running time of: O(kn)
*
* Feel free to make an initial O(n) passthrough of the array to
* determine k, the number of iterations you need.
*
* At no point should you find yourself needing a way to exponentiate a
* number; any such method would be non-O(1). Think about how how you can
* get each power of BASE naturally and efficiently as the algorithm
* progresses through each digit.
*
* You may use an ArrayList or LinkedList if you wish, but it should only
* be used inside radix sort and any radix sort helpers. Do NOT use these
* classes with merge sort. However, be sure the List implementation you
* choose allows for stability while being as efficient as possible.
*
* Do NOT use anything from the Math class except Math.abs().
*
* You may assume that the passed in array is valid and will not be null.
*
* @param arr The array to be sorted.
*/
public static void lsdRadixSort(int[] arr) {
// WRITE YOUR CODE HERE (DO NOT MODIFY METHOD HEADER)!
}
}


Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- import java.util.ArrayList;import java.util.Random; class Main { public static void main(String[] args) { Random rand = new Random(); ArrayList<Integer> a = new ArrayList<Integer>(); for(int i = 0; i < 100; i++) { a.add(rand.nextInt(100)); } print(a); System.out.println("----"); sort(a); print(a); // simplified Quicksort public static void sort(ArrayList<Integer> a) { if (a.size() <= 1) return; // Pick a Pivot int m = a.size() / 2; int pivot = a.get(m); } ArrayList<Integer> smaller = new Arraylist<Integer>(); ArrayList<Integer> same = new ArrayList<Integer>(); ArrayList<Integer> larger = new ArrayList<Integer>(); for (Integer x : a) { if (x < pivot) { smaller.add(x); } else if(x > pivot) { larger.add(x); } else { same.add(x); } } sort(smaller); sort(larger); a.clear(); a.addAll(smaller);…arrow_forwardSort the array using insertion sort algorithm list ={18,57,8,89,7}arrow_forwardIn python. Write a LinkedList class that has recursive implementations of the add and remove methods. It should also have recursive implementations of the contains, insert, and reverse methods. The reverse method should not change the data value each node holds - it must rearrange the order of the nodes in the linked list (by changing the next value each node holds). It should have a recursive method named to_plain_list that takes no parameters (unless they have default arguments) and returns a regular Python list that has the same values (from the data attribute of the Node objects), in the same order, as the current state of the linked list. The head data member of the LinkedList class must be private and have a get method defined (named get_head). It should return the first Node in the list (not the value inside it). As in the iterative LinkedList in the exploration, the data members of the Node class don't have to be private. The reason for that is because Node is a trivial class…arrow_forward
- Consider the following sorting algorithm that uses the class you wrote in the previous problem: void sort(int[] array) { SortedPriorityQueue queue = new SortedPriorityQueue(100); for (int i = 0; i < array.length; i++) queue.add(array[i]); for (int i = 0; i < array.length; i++) array[i] = queue.remove(); } Analyze its execution time efficiency in the worst case. In your analysis you may ignore the possibility that the array may overflow. Indicate whether this implementation is more or less efficient than the one that uses the Java priority queue.arrow_forwardThis codes not complie it can you fix the code can complie it? import java.util.ArrayList; public class Heap { void heapify(ArrayList hT, int i) { int size = hT.size(); int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < size && hT.get(l) > hT.get(largest)) largest = l; if (r < size && hT.get(r) > hT.get(largest)) largest = r; if (largest != i) { int temp = hT.get(largest); hT.set(largest, hT.get(i)); hT.set(i, temp); heapify(hT, largest); } } void insert(ArrayList hT, int newNum) { int size = hT.size(); if (size == 0) { hT.add(newNum); } else { hT.add(newNum); for (int i = size / 2 - 1; i >= 0; i--) { heapify(hT, i); } } } void deleteNode(ArrayList hT, int num) { int size = hT.size(); int i; for (i = 0; i < size; i++) { if (num == hT.get(i)) break; } int temp = hT.get(i); hT.set(i,…arrow_forwardGiven main() and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing the insertInDescendingOrder() method to insert new IntNodes into the IntList in descending order. Ex. If the input is: 3 4 2 5 1 6 7 9 8 -1 the output is: 9 8 7 6 5 4 3 2 1 import java.util.Scanner; public class SortedList { public static void main (String[] args) {Scanner scnr = new Scanner(System.in);IntList intList = new IntList();IntNode curNode;int num; num = scnr.nextInt(); while (num != -1) {// Insert into linked list in descending order curNode = new IntNode(num);intList.insertInDescendingOrder(curNode);num = scnr.nextInt();}intList.printIntList();}}arrow_forward