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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:08:54+00:00 2026-05-26T07:08:54+00:00

void AlgoMMPCbar::subs(const std::vector<unsigned int>& org, const std::vector<unsigned int>& pre, size_t k, size_t n, SubSets&

  • 0
void AlgoMMPCbar::subs(const std::vector<unsigned int>& org, const std::vector<unsigned int>& pre, size_t k, size_t n, SubSets& c){
   if (n <= 1) {
    for(size_t i = k; i < org.size(); i++){
        std::vector<unsigned int> v(pre);// instead of printing...
        v.push_back(org.at(i));
        c.push_back(v);
    }
} else {
    size_t n1 = n - 1;
    for(size_t i = k; i != org.size() - n1; i++){   // 
        std::vector<unsigned int> s(pre);
        s.push_back(org.at(i));
        subs(org,s,i+1,n1,c);
    }
}
}
void AlgoMMPCbar::computeSubSets(const std::vector<unsigned int>& org, size_t& n, SubSets& c){
 c.clear(); // clear previous data

std::vector<unsigned int> pre;
pre.reserve(n+1); // for performance
    if (n==0)
      c.push_back(pre);
else
        subs(org,pre,0, n, c); 
}

The above code used to generate subsets of size n for further test/processing. But i never need to test all these generated subsets (in worst case it will check them all). The main time consuming part of the program is the subset generation. Now i want to transform the above functionality to generate subsets one by one (not all at once, so, i can stop further subset generation any time).

Please share your expertise to transform the above functionality in a function like subset.next(), to save computational time.

Thanks in advance.

  • 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-26T07:08:55+00:00Added an answer on May 26, 2026 at 7:08 am

    say ind maintains the indexes for elements in the subset in an increasing order, i.e.

    ind[0] < ind[1] < ... < ind[n-1]
    

    find the smallest j such that

    j == n-1 || ind[j] + 1 < ind[j+1]
    

    you may go to the next subset by

    ind[j]++
    ind[0] = 0; ind[1] = 1; ... ind[j-1] = j-1
    

    note that the new ind array is still sorted. You may easily show that starting with

    ind[] = [0, 1, ..., n-1]
    

    you will generate all the subsets iterating through above procedure. you can have a fast code if you use some tricks for ‘maintaining’ the value of j in above rather than doing a linear search.

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

Sidebar

Related Questions

void max_idxs(vector<int> &pidxs){ vector<fragment *> ids; max_ids(ids); for(size_t i = 0; i < ids.size();
void merge(vector<int> dst,vector<int> first,vector<int> second) { int i=0,j=0; while(i<first.size()&&j<second.size()) { if(first[i]<second[j]) { dst.push_back(first[i]); i++;
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
void FileManager::CloseFile(File * const file) { for (int i = 0; i < MAX_OPEN_FILES;
void * bsearch ( const void * key, const void * base, size_t num,
void turtle (int gtot) { int msg; fcntl(gtot,F_SETFL,O_NONBLOCK); read(gtot,&msg,4); gotoxy(12, 21); printf(The value of
void weight_data::rev_seq(string &seq){ //TODO std::reverse(seq.begin(), seq.end()); } In this C++ method, I think this
void main() { const int * a; *a = 5; } gcc error :
void max_min(sqlite3 *db) { //call back********* int i, ncols; sqlite3_stmt *stmt; char *sql; const
void GameBoard::print(const GameBoard& computerBoard) { Grid[0][0] = '1'; Grid[0][1] = '2'; Grid[1][0] = '3';

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.