Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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> 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 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()); } 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(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Give an example where P[A] 0 yet P[A j B] 0.

Answered: 1 week ago