Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1102137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:08:21+00:00 2026-05-17T01:08:21+00:00

I have a problem for a university lab; Write a short program that outputs

  • 0

I have a problem for a university lab;

Write a short program that outputs all possible strings formed by using characters ‘c’, ‘a’, ‘r’, ‘b’, ‘o’, and ‘n’ exactly once.

It seems to be a common interview question and well documented.

So I’ve coded it with Java using a recursive method which wasn’t too hard, when or why would you choose not to use recursion and what would be the easiest way of doing it?

I started to code a counter that would count down on base 6, the output would then reference char’s and print the string.

Thanks,

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:08:22+00:00Added an answer on May 17, 2026 at 1:08 am

    Yes, there are plenty of times I would not use recursion. Recursion is not free, it has a cost in stack space and that can often be a much more limited resource than some others. There’s also a time cost, however small, in setting up and tearing down stack frames.

    By way of example, the much vaunted factorial function is one where I would probably opt for an iterative approach where the numbers were large. Calculating 10000! with the Python:

    def factorial (n):
        if n = 1: return 1
        return n * factorial (n-1)
    

    will attempt to use a whopping 10,000 stack frames (though Python will protect you against this). The equivalent iterative solution:

    def factorial (n):
        r = 1
        while n > 1:
            r = r * n
            n = n - 1
        return r
    

    will use just the one stack frame and precious little else.

    It’s true that recursive solutions are often more elegant code but you have to temper that with the limitations of your environment.

    Your carbon example is one where I would actually use recursion since:

    • it uses at most six stack frames (one per character in the string); and
    • it’s relatively elegant, at least much more so than six nested loops and huge equality checks.

    For example the following Python code does the trick:

    def recur (str, pref = ""):
        # Terminating condition.
    
        if str == "":
            print pref
            return
    
        # Rotate string so all letters get a chance to be first.
    
        for i in range (len (str)):
            recur (str[1:], pref + str[:1])
            str = str[1:] + str[:1]
    
    recur ("abc")
    

    producing:

    abc
    acb
    bca
    bac
    cab
    cba
    

    Of course, if your string can be 10K long, I’d rethink it, since that would involve a lot more stack levels but, provided you keep in low enough, recursion is a viable solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In short, I am currently working on a research problem for my university that
I have an annoying problem: we're supposed to write a small game for university
I have problem with my query on C, I’m using the oci8 driver. This
I have to implement an algorithm that generates a timetable for a university. I've
i have following problem from book introduction algorithm second edition by MIT university problem
I have a very weird problem.I am in an university and we are supposed
For a university course I have to write a http server which is supposed
I am generating new xml file using perl script but I have small problem,
Ok I have made a simple radio app that streams music from my university
I using devise gem for registration but i have problem. my table include: first_name,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.