Friday, September 9, 2016

#algorithm discussion continued
Today we continue reading the flow networks. We were looking at maximum flows
Maximum flows can also be calculated using "push-relabel" method.
This method performs two basic operations: pushing flow excess from a vertex to one of its neighbors and relabeling a vertex.The proof to show that preflow under such conditions becomes maximum will be discussed shortly.
We said that in a flow network represented by graph G with (V, E) as vertices and edges, let f be a preflow in G and h is a height function on V. For any two vertices u, v in the vertices V, if h(u) > h(v) + 1, then (u,v) is not an edge in the residual network. This follows from the way we have defined the operations on the flow network and the height function.
The Push operation applies only if u is an overflowing vertex, cf(u,v) > 0 and h(u) = h(v) + 1. The push operation updates the preflow f and the excess flows for u and v. It assumes that we can compute residual capacity in constant time given c and f.  The excess flow stored at a vertex u and the height are set as attributes to the vertex as u.f and u.h respectively.
The vertex u has a positive excess and the edge (u,v) has a positive residual capacity. This lets us increase the flow from u to v without u.e to become negative or the capacity c(u,v) to be exceeded by taking the minimum of the residual capacity along (u,v) and the excess flow at u. We then increase the flow with this quantity along this original edge u,v. We also decrease the same quantity from the reverse of the edge v,u  because the residual edge is the reverse of the edge in the original network.
All the flow is downward  in the flow network so all the residual edges are at the same level, one level down or upwards. If h(u) is greater than h(v) + 1, then (u,v) is not an edge in the residual network. This is why the original edge (u,v) is also a residual edge because we set h(u) = h(v) + 1 and we try to increase the flow in this direction.

#codingexercise
Void getmiddle(node head,  ref int start, ref int offset, ref node middle)
{
If (head == null) return;
Start = start  + 1;
getmiddle(head.next, k, ref count, ref offset ref middle);
Offset = offset + 1;
if (offset== start/2) { middle = head;}
}

Bool isGreater(node tree1, node tree2)
{
if (tree1 == null && tree2 == null) return true;
if (tree1 == null || tree2 == null) return false:
if(tree1.data <= tree2.data) return false;
Return isGreater(tree1.left, tree2.left) && isGreater(tree1.right, tree2.right);
}

A sorted array has been rotated r times to the left. Find r in least possible time.

Int getRotationCount(list<int> nums, list<int> sorted)
{
Return. Nums.count - Nums.merge(nums).indexof(sorted);

No comments:

Post a Comment