Question
Asked by:
TAboy26
TAboy26
Rating : No Rating
Questions Asked: 24
Tutorials Posted: 0
 

$15.00 Recursive string problem needed as Java code(I attached here file with a partial solution i managed to complete so far )

Q:
The following program MUST be ONLY recursive without any loops using at all anywhere in it..its possible using 4 string functions which i wrote after the question

Q)Write a static recursive function called maximal that is:
public static int maximal (String st1,String st2) which gets 2 strings st1,st2 and returns the length of the longest sub-string containing the chars(in any order in a row) of st1 in st2.
for example:if st1 is xyz and s2 is abxyryxzycx,the function returns 4 since is the longest combination of st1 chars in s2...(the shorter combinations were:xy and x)...

*)public char charAt(int i)-returning char located at i index.
*)public int indexOf (int ch)-returning index of the ch char,if no char at all its -1.
*)public int length()-returning the length of string
*)public String substring(int i)- returning the substring starting from the i index till the end of the string.

Thank you.

Another clarification making things easier to understand..
The charAt returns the char of i index in the related string ,and the use of it will be mostly like..
char firstChar = str.charAt(0); (puts first index char into firstChar)

 
Attachments:
solution.txt (0K)


   
   
   
   
b_h asked: I don' understand how if st1 is xyz and s2 is abxyryxzycx that the longest common substring has a length of 4 since st1 has a length of 3.
To which TAboy26 said: you are right that st1 has just 3 chars but even if its chars appear in a row like xyxyxzxyxx it will be 10 max length.. so here in st2 yxzy is 4 length (before it theres r and after it c which spoil the row).. thanx
 
Available Tutorials to this Question
Posted by:
b_h
b_h
Rating (671): A+
Questions Asked: 0
Tutorials Posted: 1188, earned $24,653.40
 

$15.00 Recursive Problem Solving

  • This tutorial was purchased 1 time and hasn't been rated yet.
  • Posted on Jan. 25, 2009 at 11:44:16AM
A:
Preview: ... ngth of the longest run of characters, so we'll want it to return the value of currentMax when st2 has nothing we can work with. This happens when st2 is empty, or startingAt tells us to look at the end of st2.<br><br>Now the recursive step. There are two cases. Either the character ...

The full tutorial is about 254 words long plus attachments.

Attachments:
Max1.java (1K) (Preview)
Posted by:
DoctorD
DoctorD
Rating (9): A-
Questions Asked: 0
Tutorials Posted: 28, earned $420.43
 

$0.25 Ignore

  • This tutorial hasn't been purchased yet.
  • Posted on Jan 25, 2009 at 12:52:42PM
A:
Preview: ... Ignore t ...

The full tutorial is about 8 words long .
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty