Meaning of a formula to develop a function

27 Views Asked by At

So I have to develop a python function maxand(S,n) that given an integer n > 0 and a set S of non-negative integers, with n < |S|, returns:

$\max_{ \{t_1,...,t_n\} \subseteq S} $ $(t_1\&...\&t_n)$

where x & y is the bit-to-bit AND operator between integers. Examples:

maxand({2,5,13},1) = 13

maxand({2,5,13},2) = 5

maxand({2,5,13},3) = 0

My problem is that I can't understand what the formula is asking me to do. For example, with n = 1, which elements of S do I have to consider to do the bitwise operation? if the set is {2,5,13} and n = 1, then $t_1$ is supposed to be 2. Then what? And for n = 2, would it be $\max_{ \{2,5\} \subseteq S} $(2&5) with $t_1$ = 2 and $t_2$ = 5?

1

There are 1 best solutions below

2
On BEST ANSWER

I assume you know what the $\&$ operator does and that your problem is with the notation $$ \max_{ \{t_1,...,t_n\} \subseteq S} \cdots . $$

That tells you to look at all the $n$ element subsets of $S$ and find the largest value of the indicated expression. So in your example, when $n=2$ there are three $2$ element subsets -you want to find the maximum of $$ 2\&5, 2\&13, 5\&13 . $$

When $n=3$ the only $n$ element subset is the whole set and the maximum is the value for that subset: $$ 2\&5\&13 . $$ (I assume that works out to be $0$; I haven't checked.)