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

Algorithms

 
AnswerRe: which one would be faster? Pin
rihdus2-Sep-07 22:21
rihdus2-Sep-07 22:21 
GeneralRe: which one would be faster? Pin
Russell'2-Sep-07 22:36
Russell'2-Sep-07 22:36 
GeneralRe: which one would be faster? Pin
Luc Pattyn3-Sep-07 5:43
sitebuilderLuc Pattyn3-Sep-07 5:43 
GeneralRe: which one would be faster? Pin
Mushtaque Nizamani2-Sep-07 22:51
Mushtaque Nizamani2-Sep-07 22:51 
GeneralRe: which one would be faster? Pin
chandu0042-Sep-07 23:17
chandu0042-Sep-07 23:17 
AnswerRe: which one would be faster? Pin
cp98763-Sep-07 0:02
cp98763-Sep-07 0:02 
AnswerRe: which one would be faster? Pin
Russell'3-Sep-07 0:13
Russell'3-Sep-07 0:13 
GeneralRe: which one would be faster? - Slightly OT Pin
blackjack21504-Sep-07 22:32
blackjack21504-Sep-07 22:32 
GeneralRe: which one would be faster? - Slightly OT Pin
Russell'4-Sep-07 22:47
Russell'4-Sep-07 22:47 
AnswerRe: which one would be faster? Pin
Chetan Patel10-Sep-07 0:43
Chetan Patel10-Sep-07 0:43 
Questioncan you tell me how to do this Pin
prasadbuddhika30-Aug-07 0:53
prasadbuddhika30-Aug-07 0:53 
AnswerRe: can you tell me how to do this Pin
cp987630-Aug-07 1:38
cp987630-Aug-07 1:38 
GeneralRe: can you tell me how to do this Pin
prasadbuddhika30-Aug-07 2:16
prasadbuddhika30-Aug-07 2:16 
GeneralRe: can you tell me how to do this Pin
cp987630-Aug-07 13:51
cp987630-Aug-07 13:51 
GeneralRe: can you tell me how to do this Pin
Russell'30-Aug-07 22:03
Russell'30-Aug-07 22:03 
GeneralRe: can you tell me how to do this Pin
Paul Conrad31-Aug-07 16:54
professionalPaul Conrad31-Aug-07 16:54 
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 
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

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.