Today, I had a chance to use Fisher Yates algorithm. Fisher Yates algorithm shuffles the items in a list.

Here is the problem statement:

Out of an array of N items, randomly pick K items where 0 < K < N.

My first naive solution of the problem was as follows:

IEnumerable<int> RandomSelect(int n, int k)
{
    var random = new Random();
    var set = new HashSet<int>();
    while(set.Count
Read More

Dijkstra’s algorithm computes the shortest distance between two vertices in a graph. Vertices in a graph are connected by an edge with a positive length.

static int SingleSourceShortestPathForNonNegativeEdgeLength(Vertex v)
{
    int min = short.MaxValue;
    var crossingEdges = new MinHeap<short, short>(N);
    var minVertices = new bool[N]; 
    minVertices[v.Id - 1] = true;
    
    foreach (var outgoingEdge in v.OutgoingEdges)
    {
        // Use a Heapify operation!
Read More