views:

142

answers:

3

Write an algorithm to check whether a set A is proper set from B or not. (Hint: proper set is that set A is subset from B but they should not be equal, the result should be either True or False, if true that means A is proper set else it is not proper set)

A: 

Is Java's collection framework allowed? :)

public boolean properSet(Set<?> a, Set<?> b) {
    return !a.equals(b) && b.containsAll(a);
}
fhd
+1  A: 

In Python:

A<B

eg:

>>> set("abcd")<set("abcde")
True
>>> set("abcd")<set("abcd")
False
>>> set("abcd")<set("abc")
False
gnibbler
nice to learn something myself on this question :)
Will
A: 

In high level pseudo-code:

  • If set A contains the same number of elements as set B, the result is false.
  • Look at each element in set A. If it is not in set B, the result is false.
  • Otherwise, the result is true.
Scott Langham
Shouldn't your first line read as follows? "If set A contains the same number of elements *or more* as set B, the result is false."
fhd
:) It could do if you want to optimize.
Scott Langham