i found another mistake in my code that it only checks for the most inner two letters and if they are the same it return true other wise it return false without taking care of the other letters in the word
Heena Agarwal wrote:Thanks Stephen. I've actually listed similar steps in my first response. Just I got confused cause the calls were returning a boolean. Just in my steps, I'm passing the same char array and the position from the starting position as the argument ( it would also be the position from the length of the array ).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Mohamad Samy wrote:finally i found the solution for all even words as following:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
S. Freeman wrote:When i think about recursion it always comes to mind as something that will save "space" for me. I am extremely lazy and i want to type as little code as possible.
S. Freeman wrote:When i think about recursion it always comes to mind as something that will save "space" for me.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Heena Agarwal wrote:Do you all also think that for this latter case also recursion is a better choice than iteration? I would have probably used simple iteration for this. But I know I might be wrong.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Heena Agarwal wrote:However with the palindrome problem (even if we ignore for the time being the long Strings ), even the complexity remained almost the same. It seemed like with every stack frame the String size reduced, but with every iteration also it would have reduced equally. So there was no added advantage of using recursion in the case of the palindrome problem.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Heena Agarwal wrote:Thank you, Winston. I shall keep these points in mind.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I remember being taught, not quite that many years ago (2009) that recursion was invented before iteration, but you can use (for example) Dijkstra's weakest precondition transformer semantics to prove that recursion and iteration are equivalent to each other.Winston Gutkowski wrote: . . . I remember being taught (many years ago
) . . .
Campbell Ritchie wrote:I remember being taught...that recursion was invented before iteration, but you can use (for example) Dijkstra's weakest precondition transformer semantics to prove that recursion and iteration are equivalent to each other.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Stephan van Hulst wrote:Note that you *probably* don't have to worry about stack overflows if your recursive calls happen at an exit point of the method.
If you perform return isPalindrome(s.substring(1, s.length()-1)) the compiler is likely to pop the current frame off the stack before it pushes the next frame on. It's called tail-recursion, and I *think* that in javac it was implemented in 1.6.
rubbery bacon. crispy tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|