Dictionary algrarithms?

hi:

here is a design for a dictionary

Design

A dictionary is essentially a set of words. Dictionaries are used in various applications.

In a spell-checker, a dictionary is used simply to decide whether a given word is

correctly spelled. In information retrieval, however, the emphasis is on determining the

given word抯 stem. For example, the stem of 搈en?is 搈an? the stem of 揼oing?and

揼one?is 揼o? and the stem of 揼reen?is itself.

Note that, in a conventional printed dictionary, all the words with a common stem are

grouped together in a single entry.

Design an abstract data type, Dictionary, that captures the notion of a set of words

grouped in this way. Dictionary must be equipped with operations that enable an

application program to:

1. make the dictionary empty;

2. add a new word to the dictionary, indicating its stem if it is not itself a stem;

3. test whether the dictionary contains a given word;

4. determine the stem of a given word;

5. print the dictionary in alphabetical order, one line for each group of words

with a common stem (first the stem, then the other words in no particular

order).

Express your design in the form of a Java interface. Each operation must be

accompanied by a specification of its observable behaviour (as a comment).

You can assume that every group of words with a common stem is small.

implementation efficiency the operationthe operation that meets requirement 5

should be O(n), whilst the operations that meet requirements 2? should be faster than O(n).

I want to implement it like a hashtable, i set the word and the stem of it to be the key and value of the entry which is to be added into the buckets of hashtable.

but only using this data structure cannot achieve the efficiency in requirement 5;

so i used an array which hold the stems and corresponding words , the "stem" are added into the array in acsending order, and if the word to be added is not a stem, just add it into the end of the created linked list which the header is pointed at its "stem" in the array.

require 2 O(1) +O(logn) = O(logn) add both in array and hashtable

require 3 O(1)seach from hashtable

require 4 O(1)seach from hashtable according key get the value

require 5 O(n)print from array

I think my solution is not a prfect one.

what are you ideas and suggestion on this program?

[2513 byte] By [charlesufoa] at [2007-10-2 15:16:17]
# 1
My suggestion is that you read the prompt carefully! It only calls for you to write an interface with comments indicating the "observable behavior". I.e., you are not supposed to provide any implementation details whatsoever - so don't beat yourself up coming up with them.Drake
Drake_Duna at 2007-7-13 14:19:19 > top of Java-index,Other Topics,Algorithms...
# 2

Interesting topic, but only writing an interface is not enough, I think it should be properly implemented by executable code.

Using a hashtable is a good way, however, a balanced search tree is an alternative way that make it works. My soluation of the "print dictionary" requriment is similar to the author's idea, anyone got better idea? O(n) it a bit hard to achieve...

K_Ghosta at 2007-7-13 14:19:19 > top of Java-index,Other Topics,Algorithms...
# 3

As i had mention about so i used an array which hold the stems and corresponding words , the "stem" are added into the array in acsending order, and if the word to be added is not a stem, just add it into the end of the created linked list which the header is pointed at its "stem" in the array.

The time complexity is O(n),so it is not a f=good solution ,

the new modify to this part is use a tree to replace the array then the time complexity is between O(logn) and O(n).

do you think it is a good solution?

charlesufoa at 2007-7-13 14:19:19 > top of Java-index,Other Topics,Algorithms...