Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-28 Thread Shiv ...
Ignore the last post. match(char * A, char *B) { char * tempA = *A; while(1) { char * tempB=*B; while(*B && *B == *A) { *B++; *A++; } if(!*B) return *tempB;

Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-28 Thread Shiv ...
Excuse the indentations, how about the following solution? O(strlen(B)). match(char * A, char *B) { char * tempA = *A; while(1) { char * tempB=*B; while(*B && *B == *A) { *B++;*A++; } if(!*B) return *tempB; else { while(*B && *B++ != *A) ; if(*B) continue; else return NULL; } //while(1) }//match

Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-27 Thread Anand
It is just an Implementation of KMP string match Algorithm. In the first section, I am find the prefix function π for a pattern which encapsulates knowledge about how the pattern matches against shifts of itself. This information can be used in second section to avoid testing useless shifts for s

[algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-27 Thread bujji
Hi Anand, Can you please explain your code? What is the magic number 10 in if(k == 10) { printf("String Matched\n"); } in your code? What does while loop do in your code? Can you please write a comment? -Thanks in advance, Bujji #include #include /* KMP

Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-22 Thread Anand
http://codepad.org/grtqfF5f Here is KMP code to solve the problem On Thu, Jul 22, 2010 at 2:01 AM, Mallesh Kavuluri wrote: > Taking for granted that KMP algorithm searches for a given string of > length n in a string of length m in O(n+m) time, > > How do we solve this puzzle in linear time? > >

Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-22 Thread Mallesh Kavuluri
Taking for granted that KMP algorithm searches for a given string of length n in a string of length m in O(n+m) time, How do we solve this puzzle in linear time? On Thu, Jul 22, 2010 at 1:29 PM, sharad kumar wrote: > @all:pls make use of KMP algorithm...because knuth morris prat algor > > > O

Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-22 Thread sharad kumar
@all:pls make use of KMP algorithm...because knuth morris prat algor On Wed, Jul 21, 2010 at 6:16 PM, anugrah wrote: > Stack can be used to push the characters of the string A and then > popped off while scanning through the string B until there is a > difference in the character read from the s

Re: [algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-21 Thread Mallesh Kavuluri
Hi Anuragh, Your stack method does not seem to work. The first element popped out of stack A will be p. But the first character in B is t. It does not match in the first step itself. -Regards, Mallesh On Wed, Jul 21, 2010 at 6:17 PM, anugrah wrote: > Stacks can be used. > > O

[algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-21 Thread anugrah
Stacks can be used. On Jul 20, 4:18 pm, mallesh wrote: > We are given two strings. A and B. > > First few letters of A match with Last letters of B. We have to find > the longest match in linear time. > Example: > char * A ="This is my first post to this group"; > char *B= "to this group this is

[algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-21 Thread anugrah
Stack can be used to push the characters of the string A and then popped off while scanning through the string B until there is a difference in the character read from the string B and the one popped off from the stack.. On Jul 20, 4:40 pm, agnibha nath wrote: > You can try rabin-carp.. > > On Ju

[algogeeks] Re: Adobe Strings matching Puzzle.

2010-07-20 Thread agnibha nath
You can try rabin-carp.. On Jul 20, 4:18 pm, mallesh wrote: > We are given two strings. A and B. > > First few letters of A match with Last letters of B. We have to find > the longest match in linear time. > Example: > char * A ="This is my first post to this group"; > char *B= "to this group thi