Saturday, August 20, 2016

Yesterday we were discussing the flow networks and the Ford Fulkerson method.  It introduced us to residual network, augmenting paths and cuts. We saw how residual networks help with maximizing flow. We read  a few lemmas for residual networks.
 The first lemma was about augmentation using the flows in both the networks. The second lemma was about the binary definition of the flow along the path.  We can combine the first and second lemma into a corollary as follows: If G is a flow network, f is a flow in G, p is an augmenting path in G and fp is defined with capacity constraint along path p and then we augment f by fp, Then the function f increased by fp is a flow in G with values individually from f and fp taken together which should exceed f.
By repeatedly augmenting, we increase the flow in the network. But to be sure we have reached the maximum, we use the max flow min cut theorem which tells us that the flow is maximum if and only if the residual network contains no augmenting path. To look into this theorem, we first describe a cut of the flow network as a partition of its vertices into set S and T = V- S such that s belongs to S and t belongs to T. As we flow is depicted by directional edges. If f is a flow, then the net flow f(S,T) across the cut is defined to be the sum of all flows over all vertices belong to S and over all vertices belonging to T in the forward direction reduced by the same in the reverse direction.
 This aggregation over the vertices of T before the aggregation over the vertices of  S is also similarly performed to compute the capacity of the cut. A minimum cut of the network is a cut whose capacity is the minimum over all cuts in the network.
#puzzle
100 coins are lying flat on a table. 10 of them are heads up and 90 are tails up. How can we split the coins into two piles such that there are same number of heads up in each pile?
We make two piles
say one has 88 Tails and 2 Heads
and the other has 2 Tails and 8 Heads
Now we just invert the second pile because the tails and heads are binary and inverting one means we balance x and 10 - x in both piles.
Taking this example, we have after inverting the second pile  8 Tails and 2 Heads.

A Policeman decided to punish a prisoner and asked him to make a statement. The prisoner should make such a statement such that he is spared. The rules are that if the statement is held true by Policeman, the prisoner will be hanged to death and if the statement is held false, the prisoner will be shot dead.
Solution: The prisoner claims he will be shot dead.  If it turns out to be true, he will be hanged which would invalidate the statement. If it turns out to be false, he would be shot which would again invalidate the statement.
Yesterday we were trying to find excel column name from given number but the idea remains the same as in the previous post. Please refer the previous post for the solution.
We try an alternative today
string ToName(int col)
{
 Stringbuilder ret;
int power = 1;
int value = col;
for (int I = 1; I < INT_MAX && Math.Pow(26,i) < value; i++)
{
 power = I;
ret.add('Z');
value -= Math.Pow(26,i);
}
int remainder = col - Math.Pow(26, power);
if (remainder % 26 == 0) ret.add('A')
else
ret.add('A' + remainder%26-1);
ret.reverse();
return ret.ToString();
}

 

No comments:

Post a Comment