Tuesday, June 23, 2015

Today we look at a few more interesting problems. We discuss Anti-Binary Sets. The problem is stated this way:
Let  Z = { 1,2 . .17}. Let us consider such subsets A (is a subset of Z) that for every x belongs to A, we have 2x belongs to A. Such subsets of A are called anti-binary. What is the largest anti-binary subset of Z? How many anti-binary subsets are there ?
The hint provided here is that we can create graphs with the vertices labeled from 1 to 17, and edges connecting m and 2m (for m = 1 to 8)
if we choose m = 1, we have a graph with five vertices and edges (1,2,4,8,16)
If we choose m = 3, we have a graph with three vertices and edges ( 3,6,12)
If we choose m  = 5, we have a graph with two vertices and edges ( 5, 10)
If we choose m = 7, we have a graph with two vertices and edges (7, 14)
The vertices that don't have connecting edges are 9, 11, 13, 15, 17.
The definition of Anti-Binary sets is that it cannot contain elements connected by an edge. We can consider each path separately, since they are not connected with each other. First, we can select all five single vertices. These are 9,11,13, 15, and 17. From the graphs with two vertices, we can select only one vertex, from the graphs with three vertices , we can select the ends and from the graph with five vertices, we can select the ends and the mid point. The maximum number of vertices that can form a binary set is a collection of these vertices.
Let us denote An as the number of anti binary sets of a path of size n. Then A1 = 2 and A2 = 3. For larger n, we split all the anti-binary sets possible into two groups - one that contains the last vertex and another that doesn't.  The number of latter ones is simply An-1 and the one containing the last vertex doesn't contain its predecessors which is An-2.
Therefore An  = An-1 + An-2
and this is the Fibonacci series.
Therefore An = Fibonacci(n+2).
The total number of anti-binary subsets of Z equals 2^5.3^2.5.13 = 18720
Courtesy:Kubica and Radoszewski

Returning back to our discussion on webhooks and callbacks, let us consider callbacks as something that each API can accept and process. The APIs should all have a predetermined method and parameters to perform for that callback. Different such sets can be specified for each API Callback

#codingexercise
Double  GetNthRootProductAlternateTermRaisedPTimesQoverPDividedQ (Double [] A,Double  p, Double q)
{
If ( A== null) return 0;
Return A.NthRootProductAlternateTermRaisedPTimesQoverPDividedQ(p, q);
}

No comments:

Post a Comment