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 6354803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:38:22+00:00 2026-05-24T22:38:22+00:00

Problem: Start with a set S of size 2n+1 and a subset A of

  • 0

Problem: Start with a set S of size 2n+1 and a subset A of S of size n. You have functions addElement(A,x) and removeElement(A,x) that can add or remove an element of A. Write a function that cycles through all the subsets of S of size n or n+1 using just these two operations on A.

I figured out that there are (2n+1 choose n) + (2n+1 choose n+1) = 2 * (2n+1 choose n) subsets that I need to find. So here’s the structure for my function:

for (int k=0; k<2*binomial(2n+1,n); ++k) {
    if (k mod 2) {
        // somehow choose x from S-A
        A = addElement(A,x);
        printSet(A,n+1);
    } else
        // somehow choose x from A
        A = removeElement(A,x);
        printSet(A,n);
    }
}

The function binomial(2n+1,n) just gives the binomial coefficient, and the function printSet prints the elements of A so that I can see if I hit all the sets.

I don’t know how to choose the element to add or remove, though. I tried lots of different things, but I didn’t get anything that worked in general.

For n=1, here’s a solution that I found that works:

for (int k=0; k<6; ++k) {
    if (k mod 2) {
        x = S[A[0] mod 3];
        A = addElement(A,x);
        printSet(A,2);
    } else
        x = A[0];
        A = removeElement(A,x);
        printSet(A,1);
    }
}

and the output for S = [1,2,3] and A=[1] is:

[1,2]
[2]
[2,3]
[3]
[3,1]
[1]

But even getting this to work for n=2 I can’t do. Can someone give me some help on this one?

  • 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-05-24T22:38:23+00:00Added an answer on May 24, 2026 at 10:38 pm

    This isn’t a solution so much as it’s another way to think about the problem.

    Make the following graph:

    • Vertices are all subsets of S of sizes n or n+1.
    • There is an edge between v and w if the two sets differ by one element.

    For example, for n=1, you get the following cycle:

     {1} --- {1,3} --- {3}
      |                 |
      |                 |
    {1,2} --- {2} --- {2,3}
    

    Your problem is to find a Hamiltonian cycle:

    A Hamiltonian cycle (or Hamiltonian circuit) is a cycle in an
    undirected graph which visits each vertex exactly once and also
    returns to the starting vertex. Determining whether such paths and
    cycles exist in graphs is the Hamiltonian path problem which is
    NP-complete.

    In other words, this problem is hard.

    There are a handful of theorems giving sufficient conditions for a Hamiltonian cycle to exist in a graph (e.g. if all vertices have degree at least N/2 where N is the number of vertices), but none that I know immediately implies that this graph has a Hamiltonian cycle.

    You could try one of the myriad algorithms to determine if a Hamiltonian cycle exists. For example, from the wikipedia article on the Hamiltonian path problem:

    A trivial heuristic algorithm for locating hamiltonian paths is to
    construct a path abc… and extend it until no longer possible; when
    the path abc…xyz cannot be extended any longer because all
    neighbours of z already lie in the path, one goes back one step,
    removing the edge yz and extending the path with a different neighbour
    of y; if no choice produces a hamiltonian path, then one takes a
    further step back, removing the edge xy and extending the path with a
    different neighbour of x, and so on. This algorithm will certainly
    find an hamiltonian path (if any) but it runs in exponential time.

    Hope this helps.


    Good News: Though the Hamiltonian cycle problem is difficult in general, this graph is very nice: it’s bipartite and (n+1)-regular. This means there may be a nice solution for this particular graph.

    Bad News: After doing a bit of searching, it turns out that this problem is known as the Middle Levels Conjecture, and it seems to have originated around 1980. As best I can tell, the problem is still open in general, but it has been computer verified for n <= 17 (and I found a preprint from 12/2009 claiming to verify n=18). These two pages have additional information about the problem and references:

    • http://www.math.uiuc.edu/~west/openp/revolving.html
    • http://garden.irmacs.sfu.ca/?q=op/middle_levels_problem
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I have an Activity where a user can start
My specific problem is that I have a set of Apache access logs, and
I have encountered the problem to start different version of jboss in the same
I have a focus problem in C# GUI with tabs. I start a process
I have a bizarre problem at the moment, I am just making a start
I have a problem with moving animation. I want to create animation which start
I'm into a problem with a GTK+ C application. I have a container that,
Let's say I have 6 records, and I set the fetch size as 2.
I have a problem where I retrieve and element from a list (list1), and
I have a textbox that may contain strings larger than the textbox size. When

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.