Java Solve Simple Java Annagrams Problem

  • Thread starter Thread starter akan
  • Start date Start date
  • Tags Tags
    Java
AI Thread Summary
The discussion revolves around enhancing a Java class designed to find anagrams from single words to sentences. The original assignment involved creating a HashMap that maps sorted sequences of letters to their corresponding anagrams using a HashSet. The new challenge is to adapt this functionality for multi-word phrases while keeping the existing database structure intact. A proposed approach includes splitting the input sentence into individual words, applying the existing anagram logic to each word, and then generating combinations of the resulting anagrams. The complexity of generating all possible combinations, especially for longer sentences, is acknowledged, with a suggestion to start with two-word combinations before scaling up. The original poster has since found a solution, indicating the discussion is now closed.
akan
Messages
58
Reaction score
0
[SOLVED] Simple Java Problem

Hello,

In my computer science class, we were assigned to design an annagrams class, which would create a HashMap of String => HashSet, a sorted sequence of letters mapped to all annagrams of those letters found in the dictionary. This was done.

Sample entries from the "database":
opst => 'spot', 'pots', 'tops', 'stop';
'act' => 'act', 'cat';

Now, the new assignment is to generalize the class such that the class could find annagrams of sentences, not just single words. And the professor is suggesting that the mapping database should remain as-is, with no further modifications. Can someone please give a hint as to how this could possibly be done "the right way"?

Sample of desired output:
'computer science' => 'cement occupiers', 'ecumenic copters'.

Thank you.
 
Last edited:
Technology news on Phys.org
I'm not sure about the right way but this is how i'd do it:

1. Convert the input string into separate words and store each word in a new string.
2. Apply whatever method you used in your initial class to produce HashSets for each of these word strings.
3. Convert these HashSets to arrays of Strings.
4. Produce a new array of strings where each string is one possible combination of the annagrams in the right order.

There's probably an easier way and I'm not sure if this helps either, perhaps some insight into how your initial class works, i mean maybe you wouldn't even need to split the string up into different words. Number 4 would probably be the most difficult to implement trying to get every combination especially with longer sentences. Perhaps it'd be easier to try and produce every combination for 2 words first and then extend the method to more when it works.
 
Thanks, but I've already found a solution. :)
The question may now be considered closed.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
13
Views
3K
Replies
1
Views
2K
Replies
5
Views
3K
Replies
1
Views
3K
Replies
5
Views
3K
Replies
1
Views
3K
Replies
2
Views
3K
Replies
1
Views
4K
Back
Top