Question

In: Computer Science

here i have a dictionary with the words and i have to find the words with...

here i have a dictionary with the words and i have to find the words with the largest size, (i mean word count for eg abdominohysterectomy) which have anagrams , like for example ,loop -> pool. Also , i have to sort them in alphabetical way so what could be the algorithm for that

public class Anagrams {
   private static final int MAX_WORD_LENGTH = 25;
   private static IArray<IVector<String>> theDictionaries =
       new Array<>(MAX_WORD_LENGTH);
   public static void main(String... args) {
       initTheDictionaies();
       process();
   }
   private static void process() {
//start here
       if (isAnagram("pool", "loop")) {                   // REMOVE
           System.out.println("ANAGRAM!");                   // REMOVE

      
//above this
   }
  
   private static boolean isAnagram(String word1, String word2) {
       boolean b = false;
       if (getWordSorted(word1).equals(getWordSorted(word2))) {
           b = true;
       }
       return b;
   }
   private static String getWordSorted(String word) {
       ISortedList<Character> sortedLetters = new SortedList<>();
       StringBuilder sb = new StringBuilder();
       for (int i = 0; i < word.length(); i++) {
           sortedLetters.add(word.charAt(i));
       }
       for (Character c : sortedLetters) {
           sb.append(c);
       }
       String sortedWord = sb.toString();
       return sortedWord;
   }
   private static void initTheDictionaies() {
       String s;
       for (int i = 0; i < theDictionaries.getSize(); i++) {
           theDictionaries.set(i, new Vector<String>());
       }
       try (
           BufferedReader br = new BufferedReader(
               new FileReader("data/pocket.dic")
           )
       ) {
           while ((s = br.readLine()) != null) {
               theDictionaries.get(s.length()).pushBack(s);
           }
       } catch (Exception ex) {
           ex.printStackTrace();
           System.exit(-1);
       }
       for (int i = 0; i < theDictionaries.getSize(); i++) {
           theDictionaries.get(i).shrinkToFit();
       }
   }
}

Solutions

Expert Solution

/*************************process()************************/

private static void process() {
//start here
       //set the word size to min
       int wordSize = Integer.MIN_VALUE;
       //To store the largest word
       String largetWord = "";
       //get the all sorted word in string
       String wordsString = getWordSorted(word);
       //create and fill the array by words
       String[] word = wordsString.split(" ");
           for (int i = 0; i < word.length; i++) {
               //compare word size
               if(wordSize<word[i].length()) {
                   wordSize = word[i].length();
                   //save the largest word
                   largetWord = largetWord+word[i];
               }
           }
          
           System.out.println("The largest word is "+largetWord+" And having size "+wordSize);
  
//above this
}

Thanks a lot, Please let me know if you have any problem....


Related Solutions

State a data structure that is suitable for storing (i) the words in a dictionary to...
State a data structure that is suitable for storing (i) the words in a dictionary to facilitate searching (ii) the set of folders you have in your computer Explain your choices.
(Python) I want to use a function called level() that takes a dictionary. Here is a...
(Python) I want to use a function called level() that takes a dictionary. Here is a dictionary with people's job and skill level. dict1 = {'Jame': {'Cleaning': 5, 'Tutoring': 2, 'Baking': 1},Pam': {'Plumbing': 2, 'Cleaning': 5}) like if I called level(dict1), the output will return {'Pam', 'James'} It finds the people's average skill level like for Pam is (2+5)/2=3.5 and sorted descending. How do I do that and how do I do it in only one return statement(using comprehension or...
The numbers of words defined on randomly selected pages from a dictionary are shown below. Find...
The numbers of words defined on randomly selected pages from a dictionary are shown below. Find the​ range and standard deviation for the set of numbers 58 62 35 50 49 61 46 78 67 33
The number of words defined on pages randomly selected from a dictionary are given below. Find...
The number of words defined on pages randomly selected from a dictionary are given below. Find the range and standard deviation for the set of numbers. 77 62 43 79 41 68 69 65 71 51 range equals= words
The number of words defined on pages randomly selected from a dictionary are given below. Find...
The number of words defined on pages randomly selected from a dictionary are given below. Find the range and standard deviation for the set of numbers. 72 52 68 51 78 43 45 64 51 5972 52 68 51 78 43 45 64 51 59    range equals = words
The numbers of words defined on randomly selected pages from a dictionary are shown below. Find...
The numbers of words defined on randomly selected pages from a dictionary are shown below. Find the​ mean, median, and mode of the listed numbers. Or is there no mean, median or mode? 38  53  67  54  34  58  55  43  31  39
I have looked at other answers on here in regards to this question. But I do...
I have looked at other answers on here in regards to this question. But I do not know what "In" stands for and those who answer are using different descriptions than I am used to. Here is the question. Number of Periods. How long will it take for $400 to grow to $1,000 at the interest rate specified? (LO1) a. 4% b. 8% c. 16%. Could someone please break this down a little further for me.
Here is what I have so far. I have created a code where a user can...
Here is what I have so far. I have created a code where a user can enter in their information and when they click submit all of the information is shown. How can I add a required field for the phone number without using an alert? <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Login and Registeration Form Design</title> <link rel="stylesheet" type="text/css" href="signin.css"> <script> function myFunction(){ document.getElementById('demo').innerHTML = document.getElementById('fname').value + " " + document.getElementById('lname').value + " " + document.getElementById('street').value + " "...
I have a python dictionary with the following format Key Type Value January str ['January 01...
I have a python dictionary with the following format Key Type Value January str ['January 01 2020', 'January 02 2019', 'January 03 2018'] June str ['June 04 2018', 'June 05 2018', 'June 06 2016] August str ['Augsut 07 2016', 'August 08 2016'] How do return the following conclusion with python code? January has the most day (1) in 2020 January has the most day (1) in 2019 June has the most days (2) in 2018 August has the most days...
Put a metric ρ on all the words in a dictionary by defining the distance between...
Put a metric ρ on all the words in a dictionary by defining the distance between two distinct words to be 2^−n if the words agree for the first n letters and are different at the (n+1)st letter. A space is distinct from a letter. E.g., ρ(car,cart)=2^−3 and ρ(car,call)=2^−2. a) Verify that this is a metric. b) Suppose that words w1, w2 and w3 are listed in alphabetical order. Find a formula for ρ(w1,w3) in terms of ρ(w1,w2) and ρ(w2,w3).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT