• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Recursion

 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ilja Preuss and ranchers
I have some psudo-code that describe a recusion, but I do not know whether it will stop or not. Is it missing the base case?

thanks for your time
Regards
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I read this, Reverse() calls itself every time it is called, so no, it will never stop. Are there some missing braces that belong with the "if" statement?
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ernest
I do not know too ^o^ as I just copy the answer given from TA and then smile
I think that only version 1 works
Version 1

Version 2

Version 3 (Original version) ambiguous one

Do the above three version work?
I wonder that is the program missing the base case?
thanks ^o^
[ December 11, 2004: Message edited by: siu chung man ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For version 3, I think you need to establish where the braces should be. This is pseudocode after all, so probably you're expected to infer the block structure from indentation. I suspect it's intended to be:

For all three of these, you should be able to determine what happens by analysis. For each one: what happens if Q has length 0? What about length 1? Or length 2? Of course, if an algorithm is broken for 0 or 1, you don't really need to analyze any more, I think.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic