We continue discussing the paper by Papadimitriou - Algorithms, Games and Internet. We started with Nash equilibrium and then we discussed Internet Equilibria. Nash equilibrium translates to solving linear programming. Unlike Nash Equilibrium, Internet Equilibria is not achieved by rational contemplation. This game is inherently coalitional. One of the theories suggests to draw the payoffs in such a way that no coalition has an incentive to secede because it cannot make more by itself than what is allocated in the coalition. This splitting of the total payoff forms a "core" but because it is conservative in definition, a game may have an empty core. The Internet equilibria can be described as a flow network with n nodes and a n x n flow matrix where each cell is the total traffic requirements between customers of i and customers of j. The Internet equilibria then translates to a problem of finding an optimum solution in a multicommodity flow problem for the overall network, achieving a flow matrix F' <= F, such that the corresponding payoffs for the nodes xi in terms of the flow matrix cell values summed over all j, are in the core of the coalition game v.
#codingexercise
Yesterday we were discussing spiral matrix traversal. The same algorithm works for anticlockwise direction as well:
#codingexercise
There is a square matrix of order n which is filled from 1 to n^2 in row major. Find the Kth element in spiral traversal of the matrix in anticlockwise direction
Example: Given n=3 and K=5.
Matrix:
1 2 3
4 5 6
7 8 9
Output: 9
By spiral order traversal we are covering
k <= n elements in the first column
k <= n+m-1 elements in the last row
k <= n+m-1+n-1 elements in the last column
k <= n+m-1+n-1+m-2 elements in the first row
else element lies in the inner matrix of dimensions m-2 rows and n-2 columns
int GetKthAntiClockWise(int[,] A, int m, int n, int k)
{
if (n <1 || m < 1) return -1;
if (k <= n)
return A[k-1, 0];
if (k <= n+m-1)
return A[n-1, k-n];
if (k <= n+m-1+n-1)
return A[(n-1-(k-(n+m-1))), m-1];
if (k <= n+m-1+n-1+m-2)
return A[0, m-1-(k-(n+m-1+n-1))];
return GetKthAntiClockWise(A.SubArray(1,1,m-2,n-2), m-2, n-2, k-(2*n+2*m-4)));
}
#codingexercise
Yesterday we were discussing spiral matrix traversal. The same algorithm works for anticlockwise direction as well:
#codingexercise
There is a square matrix of order n which is filled from 1 to n^2 in row major. Find the Kth element in spiral traversal of the matrix in anticlockwise direction
Example: Given n=3 and K=5.
Matrix:
1 2 3
4 5 6
7 8 9
Output: 9
By spiral order traversal we are covering
k <= n elements in the first column
k <= n+m-1 elements in the last row
k <= n+m-1+n-1 elements in the last column
k <= n+m-1+n-1+m-2 elements in the first row
else element lies in the inner matrix of dimensions m-2 rows and n-2 columns
int GetKthAntiClockWise(int[,] A, int m, int n, int k)
{
if (n <1 || m < 1) return -1;
if (k <= n)
return A[k-1, 0];
if (k <= n+m-1)
return A[n-1, k-n];
if (k <= n+m-1+n-1)
return A[(n-1-(k-(n+m-1))), m-1];
if (k <= n+m-1+n-1+m-2)
return A[0, m-1-(k-(n+m-1+n-1))];
return GetKthAntiClockWise(A.SubArray(1,1,m-2,n-2), m-2, n-2, k-(2*n+2*m-4)));
}