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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:43:40+00:00 2026-06-11T20:43:40+00:00

What is the best algorithm to find the sets in a finite collection of

  • 0

What is the best algorithm to find the sets in a finite collection of sets that are a subset of a specific set?

For example, if

A = {1, 2}
B = {2, 3, 4}
C = {3, 5}
D = {6}

and X = {1, 2, 3, 5}

Then, A and C are subsets of X.

Is there an algorithm that I could do this in linear time complexity?

Implementation Note: The members of the sets are generally from a very limited range, therefore, it could be a good idea to use C++ bitset to implement the algorithm. Couldn’t it?

Edit: The number of sets in the collection is generally very greater than The number of elements in X (in the example). Is there a way to do this linear in terms of the number of elements in X? Probably using hash or something?

  • 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-11T20:43:41+00:00Added an answer on June 11, 2026 at 8:43 pm

    Let’s assume for a moment 64 possible elements.

    Then, if you represent each element as a bit, you can use a 64 bits long integer to represent each set, and then: a & b is the set intersection of a and b.

    If (and only if) a is a subset of b then a & b == a.

    Of course you can use a bitset if you need more then 64 bits.

    For large range of elements, using a hash table to store (once) the superset, and then iterating the potential subsets to check if all elements are in it can be done.

    It is linear in the input size (average case).


    EDIT: (response to editted question)

    Unless you pre-stored some information on the data – it cannot be done betetr then O(|X| + n*min{m,|X|}) Where |X| is the size of the set X, n is the number of sets, and m is the average size of the sets.

    The reason for this is becasue at worst case, you need to read all elements in all set (because the last element you read for each set decides if it is a subset or not), and thus we cannot achieve better without previous knowledge on the sets.

    The suggested solutions are:

    Bitset: O(|X|*n)

    Hash solution: O(|X| + min{m,|X|}*n) (average case)

    Although the hash solution provides better asymptotic complexity, the constants are much better for a bitset- and thus the bitset solution will probably be faster for small |X|

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

Sidebar

Related Questions

What's the best algorithm to find all binary strings of length n that contain
i have heard from a friend of mine that the best algorithm for swapping
It is known that google has best searching & indexing algorithm. The also have
What is the best algorithm to find if any three points are collinear in
I just implemented a best match file search algorithm to find the closest match
Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit
Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit
I want to find the best matching algorithm to recreate an economic simulation. I
What's the best algorithm to find the smallest non zero positive value from a
I'm trying to find the best algorithm for finding a random number between 1-100

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.