Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Dear monks,

I have a little problem here. I also have a solution, but maybe someone has a better one. So the problem is as follows: I have a list of words like :

mamy dady bal foo bar ymamaa ...
and i need to find out if there is a word which reverse can be matched to any other word in my set. Example:

(reverse) (match) mamy -> ymam -> ymamaa
The easiest solution here would be to create a reverse of every word, join them to the original set, label them , sort them (lex. of course). That way 'ymam' and 'ymamaa' would be one next to another and since I have labelled them I can say in O(c) (c=constant) time if there exists a match to the reverse of 'mamy' or not.

Does anyone have a better solution to this ??

Thank you,

Baxy

Update: Thnx chordoba that is true, but i missed out one simple detail. These sets are huge. Therefore regex-ing would take much longer then my sorting suggestion. But yes you are correct (++) Thnx

Update : Yes only from the start ! :) That is also a good solution , but trie's are a bit memory heavy wouldn't you say. so that is why I thought sorting is the simplest one plus building a trie takes in practice much longer then sorting. Wouldn't you say?


In reply to searching problem by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found