Simple Java Problem

  • Java
  • Thread starter akan
  • Start date
  • #1
60
0

Main Question or Discussion Point

[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:

Answers and Replies

  • #2
93
0
I'm not sure about the right way but this is how i'd do it:

1. Convert the input string into seperate 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.
 
  • #3
60
0
Thanks, but I've already found a solution. :)
The question may now be considered closed.
 

Related Threads for: Simple Java Problem

  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
7
Views
19K
  • Last Post
Replies
18
Views
5K
Replies
6
Views
7K
Replies
3
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
2K
Replies
2
Views
739
Top