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
2010-08-16 16:50:03
+1
A:
In Python:
A<B
eg:
>>> set("abcd")<set("abcde")
True
>>> set("abcd")<set("abcd")
False
>>> set("abcd")<set("abc")
False
gnibbler
2010-08-16 16:54:47
nice to learn something myself on this question :)
Will
2010-08-16 16:56:27
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
2010-08-16 16:55:55
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
2010-08-16 19:40:19