Question

In: Computer Science

Suppose we have a collection of n different subsets of the set { 1, 2, ...,...

Suppose we have a collection of n different subsets of the set { 1, 2, ..., n } and they are in some arbitrary order, that is, we have subsets S1, S2, ..., Sn, but how many and which elements are in each of these subsets is entirely arbitrary. Suppose also that we have another subset S' of { 1, 2, ..., n }.

(a) Express a brute-force algorithm that determines whether S' equal to one of the subsets in the collection.

(b) Give a big-O worst case estimate as a function of n for the time complexity of your algorithm. To receive full credit, you must explain how you obtained your answer.

Solutions

Expert Solution

For all sets from S1 to Sn
{
   if Compare(Si,S')
   {
   print("Equal to subset "+i)
   }
}
Compare(S1,S2){
   l1 = len(S1);
   l2 = len(S2);
   if(l1!=l2)
   {
       return false;
   }
   hat=0;
   ans=0;
   for(i=0;i<l1;i++)
   {
       for(j=0;j<l2;j++)
       {
           if(S1[i]==S2[j])
           {
               S2[j] *= -1;
               hat=1;
               break;
           }
       }
       if(hat==1)
       {
           hat=0;
       }
       else
       {
           ans=1;
       }
   }
   if(ans==1)
   {
       return false;
   }
   else
   {
       return true;
   }
}


Related Solutions

1. Suppose ?:? → ? and {??}?∈? is an indexed collection of subsets of set ?....
1. Suppose ?:? → ? and {??}?∈? is an indexed collection of subsets of set ?. Prove ?(⋂ ?? ?∈? ) ⊂ ⋂ ?(??) ?∈? with equality if ? is one-to-one. 2. Compute: a. ⋂ ∞ ?=1 [?,∞) b. ⋃ ∞ ?=1 [0,2 − 1 /?] c. lim sup ?→∞ (−1 + (−1)^? /?,1 +(−1)^? /?) d. lim inf ?→∞(−1 +(−1)^?/ ?,1 +(−1)^? /?)
Let {Kn : n ∈ N} be a collection of nonempty compact subsets of R N...
Let {Kn : n ∈ N} be a collection of nonempty compact subsets of R N such that for all n, Kn+1 ⊂ Kn. Show that K = T∞ n=1 Kn is compact. Can K ever be the empty set?
Definition 1 (Topological space). Let X be a set. A collection O of subsets of X...
Definition 1 (Topological space). Let X be a set. A collection O of subsets of X is called a topology on the set X if the following properties are satisfied: (1) emptyset ∈ O and X ∈ O. (2) For all A,B ∈ O, we have A∩B ∈ O (stability under intersection). (3) For all index sets I, and for all collections {Ui}i∈I of elements of O (i.e., Ui ∈ O for all i ∈ I), we have U i∈I...
Let Ω be any set and let F be the collection of all subsets of Ω...
Let Ω be any set and let F be the collection of all subsets of Ω that are either countable or have a countable complement. (Recall that a set is countable if it is either finite or can be placed in one-to-one correspondence with the natural numbers N = {1, 2, . . .}.) (a) Show that F is a σ-algebra. (b) Show that the set function given by μ(E)= 0 if E is countable ; μ(E) = ∞ otherwise...
2. Suppose you have a collection of n items i1, i2, ..., in with weights w1,...
2. Suppose you have a collection of n items i1, i2, ..., in with weights w1, w2, ..., wn and a bag with capacity W (a) Describe a simple, efficient algorithm to select as many items as possible to fit inside the bag e.g. the maximum cardinality set of items that have weights that sum to at most W. (b) Prove your answer.
Let S be a set of n numbers. Let X be the set of all subsets...
Let S be a set of n numbers. Let X be the set of all subsets of S of size k, and let Y be the set of all ordered k-tuples (s1, s2,   , sk) such that s1 < s2 <    < sk. That is, X = {{s1, s2,   , sk} | si  S and all si's are distinct}, and Y = {(s1, s2,   , sk) | si  S and s1 < s2 <    < sk}. (a) Define a one-to-one correspondence f : X → Y. Explain...
By constructing a suitable bijection, show that the number of subsets of an n-set of odd...
By constructing a suitable bijection, show that the number of subsets of an n-set of odd size is equal to the number of subsets of an n-set of even size.
How can I prove that the number of proper subsets of a set with n elements is 2n−1 ?
How can I prove that the number of proper subsets of a set with n elements is 2n−1 ?
Prove the following stronger variant of Proposition 7.4. Suppose C is collection of connected subsets of...
Prove the following stronger variant of Proposition 7.4. Suppose C is collection of connected subsets of a metric space X and B ∈ C. Show, if for each A ∈ C, A ∩ B not equal ∅, then Γ = ∪{C : C ∈ C} is connected. [Suggestion: Consider the collection D = {C ∪ B : C ∈ C}].
Determine if the following subsets are subspaces: 1. The set of grade 7 polynomials 2. The...
Determine if the following subsets are subspaces: 1. The set of grade 7 polynomials 2. The set of polynomials of degree 5 such that P (0) = 0 3. The set of continuous functions such that f (0) = 2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT