Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-18-2005, 06:09 PM   #1 (permalink)
 
Newb Techie

Join Date: Mar 2005

Posts: 3

manu2011

Default help with an algorithm

Please help me with this one:

if s1 and s2 are two strings. we say that we extend s1 if we add a letter at the beginning or at the end of s1, but not in middle.
Ex: if s1=ababc. then both xababc and ababcx extend s1.

i have to design the best algorithm that checks if we can get from s1 to s2 by a sequence of extensions.

thanks
manu2011 is offline  
Old 03-18-2005, 06:16 PM   #2 (permalink)
 
Newb Techie

Join Date: Mar 2005

Posts: 9

mdhakk

Send a message via AIM to mdhakk
Default

in this one I think you would start by ckecking if s1==s2. If it is not, I guess you could limit s2 to however many chars s1 has, and see if they match. If they dont, you could remove the first char from s2, and recheck to see if the second way works again. If you contiued doing that until s2 was the same amount of chars as s1, you would know whether or not it was possible.
mdhakk is offline  
Old 03-18-2005, 07:00 PM   #3 (permalink)
 
Super Techie

Join Date: Mar 2005

Posts: 259

C.Ingram

Send a message via AIM to C.Ingram Send a message via Yahoo to C.Ingram
Default

Locate s1 in s2. If s1 is not in s2 (and exists, of course), you cannot extend s1 so that is becomes s2. If s1 is in s2, then it must be possible to extened s1 until it is s2.

If:
Code:
s1 = abc
and
Code:
s2 = abcde OR s2= yzabc OR s2=1gj#$imgabcei$'h4
Then s1 can be extended into s2.

If
Code:
s1 = def
and
Code:
s2 = abcde OR s2= yzabc OR s2=1gj#$imgabcei$'h4
Then s1 cannot be extended into s2.
__________________
Christopher Ingram
Principal Consultant, Souken Group, LLC.
C.Ingram@SoukenGroup.com
(856) 392 5244 -- (866) Go Souken
C.Ingram is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On