Click here to Skip to main content
15,891,033 members
Home / Discussions / Algorithms
   

Algorithms

 
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 
AnswerRe: Substring Matching (Harder than it sounds) [modified] Pin
Skippums29-Aug-07 7:42
Skippums29-Aug-07 7:42 
OK. I have thought about it some more, and have come up with the following solution:

Let lstr be the longer string and sstr be the shorter string...

First, I will build a dictionary with characters as keys and a singly linked list of integer indexes as the value, which will represent lstr. This table will take O(lstr.len) memory and O(lstr.len) time to build, but will be keyed in O(1) time.

Then I will make the following recursive function, which is sent the lookup table, the two strings, and an integer representing the longest string found thus far:

1. If the longest string found is longer than sstr sent in, return empty string.
2. Initialize result to be the empty string.
3. Choose character c from sstr to be the center character.
4. For each index in the dictionary for c, find the matching substring (match).
5. If match.len from (3) > result.len declared in (1), result = match. If more indexes occur for c in the dictionary, go back to (3)
6. If result.len > sstr.len / 2, return result.
Else
resultLow = recursively call this using sstr.substr(0, sstr.len / 2) and
resultHigh= recursively call this using sstr.substr(sstr.len / 2)
return the longest of (result, resultLow, resultHigh)

This will limit my searches so I don't have to waste my time comparing things that are already found. I think this algorithm will turn out to be O(lstr.len * log(lstr.len)). Any thoughts?


-- modified at 14:28 Wednesday 29th August, 2007
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 
GeneralRe: Need some intelligent people... Pin
Paddy Boyd29-Aug-07 3:55
Paddy Boyd29-Aug-07 3:55 

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.