In Java,
Write a function to perform bucket sort on a list of strings.Test the function to see if it really works in linear time on average. Finally, compare the performance of the function with Java sort method for lists.
Bucket sort on list of Strings
public void sort(String[] array)
{
if(array.length == 0)
return ;
//find the max length
int max=0;
for(int i=1; i<array.length; i++)
{
//update max length
if(max < array[i].length())
max=array[i].length();
}
//initialize the buckets
int bucketCount=26; //alphabets
//buckets in maps
HashMap<Character, Vector<String>> buckets=new HashMap<Character, Vector<String>>(bucketCount);
//create the buckets
char a='a';
for(int i=0; i<=bucketCount; i++; a++)
{
buckets.put(a, new Vector<String>());
}
//assign String array values into the buckets
for(int i=0; i<array.length; i++)
{
//get the first letter of the String word
String current=array[i];
char letter=current.toLowerCase().charAt(0);
buckets.get(letter).add(array[i]);
}
//sort the buckets and put them into input array
int index=0;
for(char key='a'; key<='z'; key++)
{
//retrieve the bucket
Vector<String> bucket=buckets.get(key);
//perform sort on bucket
for(int i=1; i<bucket.size(); i++)
{
String temp=bucket.get(i);
bucket.remove(i);
int j;
for(j=i-1; j>=0 && bucket.get(j).compareToIgnoreCase(temp) > 0; j--)
{
bucket.add(j+1, bucket.get(j));
bucket.remove(j);
}
bucket.add(j+1, temp);
}
//pile the current bucket back into array
for(int j=0; j<bucket.size(); j++)
array[index++]=bucket.get(j);
}
}
In Java, Write a function to perform bucket sort on a list of strings.Test the function...
In Java, Bucket sort is a sorting algorithm that has O(n) performance on average. I want you to write a function to perform bucket sort on a list of strings. I also want you to test your function to see if it really work in linear time on average. This code will need to be tested. Finally, I want you to compare the performance of your function with Javasort method for lists.
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?
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?
PYTHON: Do not use the list sort method or sorted function. Given a list of numbers in random order, write an algorithm that works in O(n2) to sort the list. Do not use the list sort method or sorted function. Please DO NOT USE list_sort method. the last answer did not work.
Write a Java program that will create a random list (array) randomize a search item to be found in the list sequentially search the array for that item. You must code the search and not use a search function. Display each comparison in the array; the element contents and the index. display whether the item was found or not. Now take that code and alter it to have two lists. Both lists randomize between 1 and 50. While traversing one list,...
Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...
use python Write a function that will sort a given list using merge sort. You must use the merge sort algorithm (but may be recursive or iterative). The function will take a list as an input and return a sorted version of the list (you may assume it will be a list of integers). The method signature must be merge_sort(lst).
//Java (Sort ArrayList) Write the following method that sorts an ArrayList: public static > void sort(ArrayList list) Write a test program that does the following operations: 4. Creates an empty ArrayList of Integer elements; 5. Generates 20 integer values, drawn at random between 0 and 9 (included), and adds them to the array list; 6. Calls the method sort and prints both the original list, and the sorted one.
Write Java code (do not use Java libraries) to perform the following on a linked list of integers: prepend a new value
Discrete Mathematics
Unsorted and Sorted Lists For linear search there was no requirement for the list to be organized in any manner. The linear search works for lists that are "unsorted." But what if the values in the list are given in ascending order? This would be a sorted list. With a sorted list, is there a more efficient way to find the target? Unsorted Lists (4 pts) Assume there is a sorting algorithm with order of growth O(n), where...