Click here to Skip to main content
15,909,591 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: can you tell me how to do this Pin
Tim Craig31-Aug-07 17:59
Tim Craig31-Aug-07 17:59 
AnswerRe: can you tell me how to do this Pin
Russell'30-Aug-07 8:00
Russell'30-Aug-07 8:00 
QuestionData Sample Synchronization Pin
Anthony988729-Aug-07 7:52
Anthony988729-Aug-07 7:52 
AnswerRe: Data Sample Synchronization Pin
Russell'29-Aug-07 8:16
Russell'29-Aug-07 8:16 
QuestionSubstring Matching (Harder than it sounds) [modified] Pin
Skippums29-Aug-07 5:54
Skippums29-Aug-07 5:54 
AnswerRe: Substring Matching (Harder than it sounds) Pin
Russell'29-Aug-07 6:21
Russell'29-Aug-07 6:21 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Skippums29-Aug-07 6:30
Skippums29-Aug-07 6:30 
AnswerRe: Substring Matching (Harder than it sounds) Pin
Luc Pattyn29-Aug-07 6:32
sitebuilderLuc Pattyn29-Aug-07 6:32 
Hi,

I can offer a few ideas that may reduce the size of the problem:

1. remove in string1 all chars that don't occur in string2 and vice versa;
this process typically shortens the strings, and reduces the problem to a
larger number of much smaller problems.
In your example it replaces ("abacadaba", "dbaadabb")
by ("aba", "dbaadabb") and ("adaba", "dbaadabb") based on 'c'
and the first of these can be reduced further based on 'd'.

2. search for small patterns that occur in one and not in the other string.
Again in your example that would be "aa", allowing a further reduction (here
you can split in between the two a's).

3. Once you have sufficiently reduced you could consider your quadratic cost
approach.

4. but as an alternative you could do a kind of binary search on the match length:
- start with an arbitrary length, in the shorter string, select some substring
with that length, and try to find it in the other string. If you find one,
the match can only be that size or larger. If you don't find one, you could
try all other substrings or fall back to a smaller length.
It all depends on the kind of data you want to handle well. Your example is not
a real indication I guess.

Smile | :)




Luc Pattyn [Forum Guidelines] [My Articles]


this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google


AnswerRe: Substring Matching (Harder than it sounds) [modified] Pin
Skippums29-Aug-07 7:42
Skippums29-Aug-07 7:42 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Russell'29-Aug-07 8:06
Russell'29-Aug-07 8:06 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Skippums29-Aug-07 8:28
Skippums29-Aug-07 8:28 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Russell'29-Aug-07 9:02
Russell'29-Aug-07 9:02 
AnswerRe: Substring Matching (Harder than it sounds) Pin
PIEBALDconsult29-Aug-07 18:03
mvePIEBALDconsult29-Aug-07 18:03 
AnswerRe: Substring Matching (Harder than it sounds) Pin
Mark Churchill29-Aug-07 18:26
Mark Churchill29-Aug-07 18:26 
AnswerRe: Substring Matching (Harder than it sounds) Pin
cp987629-Aug-07 23:55
cp987629-Aug-07 23:55 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Skippums30-Aug-07 4:04
Skippums30-Aug-07 4:04 
AnswerRe: Substring Matching (Harder than it sounds) Pin
Skippums4-Sep-07 11:23
Skippums4-Sep-07 11:23 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Luc Pattyn4-Sep-07 13:06
sitebuilderLuc Pattyn4-Sep-07 13:06 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Skippums4-Sep-07 13:26
Skippums4-Sep-07 13:26 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Luc Pattyn5-Sep-07 9:00
sitebuilderLuc Pattyn5-Sep-07 9:00 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Skippums5-Sep-07 10:46
Skippums5-Sep-07 10:46 
GeneralRe: Substring Matching (Harder than it sounds) Pin
Member 419459329-Mar-08 9:55
Member 419459329-Mar-08 9:55 
QuestionNeed some intelligent people... Pin
Paddy Boyd29-Aug-07 2:20
Paddy Boyd29-Aug-07 2:20 
AnswerRe: Need some intelligent people... Pin
Luc Pattyn29-Aug-07 2:56
sitebuilderLuc Pattyn29-Aug-07 2:56 
GeneralRe: Need some intelligent people... Pin
Paddy Boyd29-Aug-07 3:42
Paddy Boyd29-Aug-07 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.