Java help

I have this problem posted in http://img97.imageshack.us/my.php?image=albsin9.jpg however i dont understand what the question is asking about and do not know how to solve it. Hope someone can help me on this problem and so i can start and ***i must say this is a homework *** so i dont want whole program to be posted.

You guys go to the same school or something? :)
Anyways, it's heyhey84's question, so I'll put your questions aside for now. If you read all the articles I posted, and follow this thread, you should be able to figure it out.

>> Firstly how to convert the string to a integer value without using the hashCode()?

Read the following articles, and tell us which part you can't figure out:

>> (there are at most 25 * length of work neighbours) i have already done that, but i what i am suppose to do with this?

If I read the assignment correctly, this method is already provided as a method called "generateNeighbours". And as what to do with that, quoting your assignment:

"A better strategy is to first construct a hash table from the dictionary, so that given any word you can generate all possible neighbouring words and for each one you only need to check whether it is in the hash table."

You need BFS because that is what this assignment is about. It is also a good algorithm to use to find paths from one place to another, which is what this word ladder is all about. The picture in the article about the German cities might help you visualize what you are trying to accomplish. (The BFS part, at least.)

This part is your homework. Requirement #2: "You are required to implement your own hash function for Strings,"

The simplest hash function is to return a constant. However, this implementation is far from practical. (But it fulfills all requirements for a hash function.)

The most intuitive hash function for words would be to convert it to the page the word is listed in a dictionary. That's not possible with programming, but you can simulate it by passing the ASCII value of the first letter. (A 26 page dictionary!) However, this is also far from practical.

It's incremental learning. Even if you don't see the entire picture at the beginning, if you do it step by step, your questions are answered on the way. The professor is good at giving the assignment. :)

>> Need more specific detail like what method (add and get) etc

You basically only need a put and get as public methods.

>> add into what data structure? what data structure to use?

Read the hash table article for how a hash table is structured. It even has some pseudo-code!

Below is the where i have done. Can u help me see am i correct?
Did i implemented the hashFunction and hashTable correctly?
Am i on the right Track for my assignment?
Because i do not have a clear picture in mind how to do a BFS
I just follow the step u mention
Below is implemention of Step 1 and Step 2 :)

So the generateNeighbours method you need to implement by yourself. :)
Looks OK.

hashFunction : looks OK.

myhashTable : You will need to be able to convert the word to a List<String>. So, instead of taking in the key, you will need to take in the word. This is because two different words might have the same hash result, in which case you will not be able to retrieve the correct neighbours.

As for the BFS, you might want to go through the article again, especially the "How it works" section. I find the two diagram of finding the path from Frankfurt to Munchen quite helpful. You can ignore the distance part, as that is irrelevant in your case (the distance is always 1).

I want to foucs on the BFS so as i can somehow complete my program and tune it when everything is done. So i presume that my program above is ready to go for BFS :)

Given Dictionary
dot
cat
cot
dog
start -> cat end ->dog

BFS
Step 1 - hashFunction start-->"cat" and look for all neighbour
Step 2 - in Lexicographical order look into the neighbour 1 by 1 until there is one contain in Given Dictionary -> set it to current
step 3 - recursively search until current == end then return the step

That would be one way to search for a Word Ladder, but that does not use the BFS algorithm. Read the "How it works" and "Algorithm (informal)" section to understand what the concept of BFS is. And you can try converting the "Pseudocode" section to java to give it a try.

#
Instead of storing the distance from the start, you should store a value which indicates the “parent” of a word. The parent of a word w is the word which caused w to be added to the queue.
#
After completing the breadth first search starting from the start word, we simply start from the end word and trace the parent links to retrieve the actual word ladder.

Which part of the article don't you understand? If you don't understand BFS, you won't be able to go further. Actually, you can by blindly implementing it from the "Pseudocode" section, if coding it lets you understand the algorithm better.

Connect all the ones you answered "yes" to with lines, and you have your left diagram.

Now take a look at "cat". This would become the "Frankfurt" in the right diagram.
Which words is it connected to? Those would become the "Mannheim", "Wurzberg", "Kassel" in the right diagram. And so forth.

Now where is "dog"? With BFS, you will start with "cat", go to the next row from left to right, then to the next from left to right, an so on until you reach "dog".

Are "dot" and "cat" 1 letter apart? NO
Are "dot" and "cot" 1 letter apart? YES
Are "dot" and "dog" 1 letter apart? YES
Are "cat" and "cot" 1 letter apart? YES
Are "cat" and "dog" 1 letter apart? NO
Are "cot" and "dog" 1 letter apart? NO
-->
Ans in this way is pretty easy

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects.
Interface Comparable is used to allow objects of a cl…

Java had always been an easily readable and understandable language. Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…