wu :: forums
« wu :: forums - Find a string inside a 2-dimensional array »

Welcome, Guest. Please Login or Register.
Apr 26th, 2024, 2:29pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   microsoft
(Moderators: Grimbal, Eigenray, Icarus, SMQ, william wu, ThudnBlunder, towr)
   Find a string inside a 2-dimensional array
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Find a string inside a 2-dimensional array  (Read 8930 times)
Ved
Junior Member
**





   


Gender: male
Posts: 53
Find a string inside a 2-dimensional array  
« on: Jun 30th, 2012, 11:50pm »
Quote Quote Modify Modify

In a matrix of characters, find an string. String can be in any way (all 8 neighbors to be considered), like find Microsoft in below matrix.
 
A-C-P-R-C
X-S-O-P-C
V-O-V-N-I
W-G-F-M-N
Q-A-T-I-T
 
String Microsoft is present in the matrix above ?
There also a slight variation where a diagonal neighbor is not considered.
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Find a string inside a 2-dimensional array  
« Reply #1 on: Jul 1st, 2012, 1:11am »
Quote Quote Modify Modify

Consider the matrix as a graph with neighbours connected, and then you can just do depth first search or something.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
R
Senior Riddler
****



Addicted!!!

   


Gender: male
Posts: 502
Re: Find a string inside a 2-dimensional array  
« Reply #2 on: Sep 14th, 2012, 8:21pm »
Quote Quote Modify Modify

on Jul 1st, 2012, 1:11am, towr wrote:
Consider the matrix as a graph with neighbours connected, and then you can just do depth first search or something.

 
As the string can be hidden anywhere and in any shape (just like the one given in example), I agree that graph seems to be a good choice.
 
But representing the matrix and neighbors in Graph will be quite expensive. There will be n2 nodes. Next adding edges to Adjacency matrix/list will be again expensive.  
 
Now once the graph is ready and we start the DFS,  
1. From which node do we start the DFS?
2. In DFS each node is visited max twice, so while looking for a string, if some node/character is already visited twice, we won't be able to find it again.  
 
Right?
« Last Edit: Sep 14th, 2012, 8:22pm by R » IP Logged

The first experience seems like Magic, but the second tells you the Trick behind it.
softsec
Newbie
*





   


Posts: 2
Re: Find a string inside a 2-dimensional array  
« Reply #3 on: Jan 27th, 2013, 2:19am »
Quote Quote Modify Modify

Is right?
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board