bfs

hey, i haven't written out the code for this yet, but i wrote it out interms of notes and i was just curious if someone wants to look them over and tell me if they think this is correct.

requirement:

Using the breadthFirstSearch method, implement a method to compute and return a shortest path (in hops) between a pair of given vertices. The method should have the following header:

String[] shortestPath(String source, String destination)

The String array that is returned should contain a sequence of vertices that corresponds to a shortest path from the source vertex to the destination vertex. Thus slot 0 in this String array should contain source and the last slot in this String array should contain destination. The length of this array should be exactly equal to the length of a shortest path from source to destination.

what i've 'written':

string[] shortestPath ( String source, String destination)

source = 0;
destination

in shortestPath[], first slot is source

for words differing by one letter, store in shortestPath[source + 1]
then [source + 1] becomes source, continue until destination is equal to shortestPath[destination -1]

somehow compare multiple paths from source to destination.

array with smallest index (should index the 'hops', or number of words from source to destination) is returned

i suppose my biggest problem is going to store all the hops into arrays, will i have to use many arrays, or can i have it all take place in one array?
[1621 byte] By [rhinomist] at [2007-11-20 11:28:59]
# 1 Re: bfs
okay, we have another class that has a bfs method, but i'm not sure where to put it in the following code...

String[] shortestPath(String source, String destination)
{

String source = shortestPath[source];
for(int i = 0; i < mg.numVertices; i++)
{
shortestPath = mg.getNeighbors(i);

for(int j = 0; j < shortestPath.length; j++)
{
if(mg.degree(destination))
System.out.println("source " + mg.names[source] + "destination " + mg.names[destination]);
}
}



}
rhinomist at 2007-11-10 2:14:05 >