I had to do something like this with a large list of words to search
for. If you're just looking for one word, look for the first letter,
and when you find it, look at adjacent locations for the second
letter. If found, continue in that direction matching letters until
you either match the whole word or don't.

But for a big list of words to search for, it was faster to do
something like this:
Build a frequency count for each character, along with a list of
ordered pairs indicating where that character is located. Then, to
look for a word, find the character with the smallest frequency count
and step through the list for that character. At each location, look
for the character before/after that character in the word on opposite
sides of the initial location, and continue from there.

Don

On Sep 14, 2:47 pm, Arun Kindra <reserve4placem...@gmail.com> wrote:
> *You have given any n*n matrix in which characters are stored and you have
> to search that a given word is present or not.(words can be horizontally,
> vertically, diagonally)*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to