richierich
BAN USERSince there are four variables to compare you can add all four variables a+b+c+d. If each has value 200, then the end result should be 800.
Do a left shift operation on the number 200 by 2 times to multiply the number by 4.
e.g 200 << 2
This is the most efficient way to multiply a number in a multiple of 2^x in just one cpu instruction. where x is the number of left shifts.
This will make the number 200 as 800.
You will need atleast one comparision. It does not matter whether the comparision is in a return statement or it is if/switch-case statement. I dont think there is any other way to compare.
#define TRUE 1
#define FALSE 0
int checkNumber(int a, int b, int c, int d)
{
if((a+b+c+d) == (200<<2)){
return TRUE;
}
else{
return FALSE;
}
}
You can use disjoint sets which has 3 operations - MakeSet, FindSet, UnionSet.
- richierich October 07, 2016UnionSet takes two vertex of the graph and and combine them in one vertex. E.g when you run union operation on a edge (A-B) you are effectively creating a representative of the set.
E.g Say
union(A, B) => A
union(B,C) => A
union(C,D) => A
union (B,Z) => A
The union operation can be maintained in a tree like structure where two nodes are inserted in a tree and one becomes the root.
Before adding any nodes in a tree you need to run findset operation on each node to find out what is the node that is representing that vertex.
e.g To do union(A,B) do a findSet(A) = A, and then do findSet(B) = B.
Since they both are in a unique set anyone can become root and other becomes a child node. Say A is the root.
Now union(B,C) => findSet(B) = A, and then do findSet(C) = C.
If you apply union by rank operation A gets priority to maintain the root, and C becomes a child node of A.
So union(B,C) = A.
FindSet(v) will take any given vertex v in the tree and will trace it to its root and return the root node.