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

  • Home
  • SEARCH
  • 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 8558797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:53:36+00:00 2026-06-11T15:53:36+00:00

I am looking for an algorithm which takes as input a set of two

  • 0

I am looking for an algorithm which takes as input a set of two elements T = {0, 1} and k and generates all k-combinations of T as follows:

000
001
010
011
100
101
110
111

It is straightforward to implement iteratively when k is small, like k=3 in the above example. Any ideas how to design a recursive algorithm so that algorithm is independent of k.

  • 1 1 Answer
  • 0 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-06-11T15:53:37+00:00Added an answer on June 11, 2026 at 3:53 pm

    You can do it recursively. Assuming that this is a learning exercise of sorts, I would give you pseudocode instead of a C program:

    generate (int pos, int element[T], int current[N])
        if pos == N
            print (current)
            return
    
        for i : 0..T
            current[pos] = element[i]
            generate(pos+1, element, current)
    
    end
    

    The top three lines are a base case. pos starts at zero, and indicates the position in the current array that needs to be filled by the current level of the recursive invocation. Once pos reaches N, we print the current combination and return to the prior level.

    The bottom three lines are a loop, similar to the nested loops in a solution to the problem when k=3. The “nesting” happens dynamically through recursion: you can think of the next level of the recursive invocation as another level of “loop nesting”. Essentially, the recursive solution lets you build N nested loops, where N is known only at run-time.

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

Sidebar

Related Questions

I am looking for an algorithm that could find the two most distant elements
I'm looking for an algorithm which can take two sets of integers (both positive
I am looking for a simple but efficient Objective-C algorithm which, starting from a
I am looking for a command line either for an algorithm (script) which allows
I'm looking for a javascript diff algorithm implementation or library, which has been tested
I am looking for a algorithm that takes a string and splits it into
I'm looking for an algorithm which someone has access to that will compute the
I'm looking for a packing algorithm which will reduce a regular polygon into rectangles
My algorithm produces a list of (usually) several thousand line segments (all 2D) which
I have a function which takes two arrays containing the tokens/words of two texts

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.