• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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: 24204
44
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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic