Write a radix sort that works with String objects, that sorts the strings in alphabetical order, and is case-insensitive. write a version that can do this with a set of String objects that are all of EXACTLY THE SAME LENGTH.
java
package Sort;
import java.util.*;
public class RedixSortString
{
/*
* Method to perform radix sort
* Parameter:
* stringWords - Array of string contains words
* maximumLength - maximum length of the string
* Assuming all string length is same (considering 5)
*/
public static void radixSort(String [] stringWords, int
maximumLength)
{
// Creates a constant for maximum bucket of size
256
// for each ASCII value
final int MAXBUCKETS = 256;
// Creates an array list to store words by its length
ArrayList<String> [] wordsBasedOnLength = new
ArrayList[maximumLength + 1];
// Creates an array list for storing words in bucket of size
256
ArrayList<String> [] bucketsForWord = new
ArrayList[MAXBUCKETS];
// Loops till length of the words by length array list to
// create each array list
for(int index = 0; index < wordsBasedOnLength.length;
index++)
wordsBasedOnLength[index] = new
ArrayList<>();
// Loops till maximum number of buckets to create each bucket
// to store words
for(int index = 0; index < MAXBUCKETS; index++)
bucketsForWord[index] = new ArrayList<>(
);
// Loops till end of the parameter stringWords string array
// Extracts each word
for(String word : stringWords)
{
// Adds the current word to wordsBasedOnLength array
list
// at the index position of the current word
length
wordsBasedOnLength[word.length()].add(word);
}// End of for loop
int index = 0;
// Loops till end of the array list wordsBasedOnLength
// to extract all words
for(ArrayList<String> currentWord : wordsBasedOnLength)
{
// Loops to get each word from currentWord array
list
for(String word : currentWord)
{
// Assigns the word at current
index position of
// parameter wtringWords
stringWords[index++] = word;
}// End of inner for loop
}// End of outer for loop
// Stores number of words in the parameter stringWords
int countWords = stringWords.length;
// Loops from end of the length to beginning based on the
parameter
// maximum length of the word
for(int indexPosition = maximumLength - 1; indexPosition >= 0;
indexPosition--)
{
// Counts number of words present at current index
position plus one
// index position of the array list
wordsBasedOnLength
countWords -= wordsBasedOnLength[indexPosition +
1].size();
// Loops from current count words to number of words in the
// parameter stringWords
for(int counter = countWords; counter < stringWords.length;
counter++)
// Stores the character at indexPosition of counter
index position
// of parameter stringWords and add it to
bucketsForWords array list
bucketsForWord[stringWords[counter].charAt(indexPosition)].
add(stringWords[counter]);
// Assigns countWords value to index
index = countWords;
// Loops till end of the bucketForWords array list
// Extracts all words
for(ArrayList<String> currentWordInBucket :
bucketsForWord)
{
// Extracts each word from currentWordInBucket
for(String word : currentWordInBucket)
// Adds the current word at current index position
of
// parameter stringWords
// Increase the index counter by one
stringWords[index++] = word;
// Clears the bucket
currentWordInBucket.clear();
}// End of inner for loop
}// End of outer for loop
}// End of method
// main method definition
public static void main(String [] ss)
{
// Creates an object of class Random
Random random = new Random();
// Declares an array of string of size 10 to store words
String [] stringArray = new String[10];
// Defines a constant for maximum length of each word
final int MAXLEN = 5;
// Loops 10 times to generate 10 words
for(int wordCounter = 0; wordCounter < 10; wordCounter++)
{
// To store the random word generated
String randomWord = "";
// Loops till maximum length of each word (I have taken 5)
for(int counter = 0; counter < MAXLEN; counter++)
// Generates random character between 'A' and
'Z'
randomWord += (char) ('A' + random.nextInt(26));
// Assigns the random word at wordCounter index position of
// stringArray
stringArray[wordCounter] = randomWord;
}// End of for loop
System.out.println("\n\n \t *********** Before Radix Sort
*********** \n");
// Loops till end of the stringArray and displays each word
for(int i = 0; i < stringArray.length; i++)
System.out.print(stringArray[i] + ", ");
// Calls the method to perform radix sort
radixSort(stringArray, MAXLEN);
System.out.println("\n\n \t *********** After Radix Sort
*********** \n");
// Loops till end of the stringArray and displays each word
for(int i = 0; i < stringArray.length; i++)
System.out.print(stringArray[i] + ", ");
}// End of main method
}// End of class
Sample Output 1:
*********** Before Radix Sort ***********
BLMET, ACERB, CUEAQ, GVLVB, FTCGA, YGDFA, EAGFO, YOAEZ, XJGZD, NIGJW,
*********** After Radix Sort ***********
ACERB, BLMET, CUEAQ, EAGFO, FTCGA, GVLVB, NIGJW, XJGZD, YGDFA, YOAEZ,
Sample Output 2:
*********** Before Radix Sort ***********
IFBYM, KEPDI, YKFBP, YERTN, ZSIDJ, YZZVJ, WLIDE, NUYII, NDERN, MBGTG,
*********** After Radix Sort ***********
IFBYM, KEPDI, MBGTG, NDERN, NUYII, WLIDE, YERTN, YKFBP, YZZVJ, ZSIDJ,
Write a radix sort that works with String objects, that sorts the strings in alphabetical order,...
write a C++ program that accepts N strings and sorts the strings in alphabetical order
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....
(Sort ArrayList) Write the following method that sorts an ArrayList: public static > void sort(ArrayList list) Write a program to test the method with three different arrays: Integers: 2, 4, and 3; Doubles: 3.4, 1.2, and -12.3; Strings: "Bob", "Alice", "Ted", and "Carol" This program is similar to the Case Study in the book: Sorting an Array of Objects The language must be written, compiled, and run on TEXTPAD. The Language is in Java.
***PLEASE USE C++ LANGUAGE*** Binary Search of Strings 1. Write a version of the selection sort algorithm presented in the unit, which is used to search a list of strings. 2. Write a version of the binary search algorithm presented in the unit, which is used to search a list of strings. (Use the selection sort that you designed above to sort the list of strings.) 3. Create a test program that primes the list with a set of strings,...
Part 1: Extend your sorting framework with 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 to work with real numbers? If yes,...
1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...
Write a method will accept an array of Strings. This method should return the string that comes after all the other strings in lexicographical order. (Assume all the Strings only contain lower case letters. In Example: No number, no Capitals and no Symbols) lastString({“hola”, “word”, “night”, “boom”}) → “word” lastString({“java”, “is”, “so”, “much”, “fun”}) → “so” lastString({“i”, “love”, “java”}) → “love” //precondition: words.length >0 public static String lastString(String[] words) { }
Write a PYTHON program that reads in three strings and sorts them lexicographically. Do NOT user the sort function. Enter string 1: Charlie Enter string 2: Able Enter string 3: Baker Able Baker Charlie Your code with comments A screenshot of the execution Test Cases: Able, Baker, Charlie Baker, Charlie, Able Charlie, Able, Baker Able, Charlie, Baker Baker, Able, Charlie Charlie, Baker, Able
Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two strings while ignoring the case of alphabetical characters. Your program will take two strings as input from the user and use your function to compare them. Assume a maximum C-string size of 1000 characters. Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. Please properly comment your...
Java, Please implement the way the interface specifies. Part A:Radix Sort Implement a radix sort as described in the last section of Chapter 7 in your text. It should handle variable amounts of data and variable numbers of digits in the key values. Use testing to ensure radix sort works for at least three examples of different input sizes and various max digit length. I need to implement the radix sort using the below java interface. /** * <h1><LeastSignificantDigit Radix...