Detect Cycle in a Directed Graph - Summary


Detect Cycle in a Directed Graph | GeeksforGeeks
Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false.
https://algorithms.tutorialhorizon.com/graph-detect-cycle-in-a-directed-graph/
Graph contains cycle if there are any back edges. There are two types of back edges as seen in the example above (marked in red)
  1. Edge from a vertex to itself. Self loop. (4-4)
  2. Edge from any descendent back to vertex.
Use DFS(Depth-First Search) to detect the back edge
  • Do the DFS from each vertex
  • For DFS from each vertex, keep track of visiting vertices in a recursion stack (array).
  • If you encounter a vertex which already present in recursion stack then we have found a cycle.
  • Use visited[] for DFS to keep track of already visited vertices.
How different is recursion stack[] from visitied [].
  • Visited[] is used to keep track of already visited vertices during the DFS is never gets
  • Recursion stack[] is used from keep track of visiting vertices during DFS from particular vertex and gets reset once cycle is not found from that vertex and will try DFS from other vertices.
  • See the code from more understanding.
Time Complexity: O(V+E)
  static class Graph {
    int vertices;
    LinkedList<Integer>[] adjList;

    Graph(int vertices) {
      this.vertices = vertices;
      adjList = new LinkedList[vertices];
      for (int i = 0; i < vertices; i++) {
        adjList[i] = new LinkedList<>();
      }
    }

    public void addEgde(int source, int destination) {
      adjList[source].addFirst(destination);
    }

    public boolean isCycle() {
      boolean visited[] = new boolean[vertices];
      boolean recursiveArr[] = new boolean[vertices];

      // do DFS from each node
      for (int i = 0; i < vertices; i++) {
        if (isCycleUtil(i, visited, recursiveArr))
          return true;
      }
      return false;
    }

    public boolean isCycleUtil(int vertex, boolean[] visited, boolean[] recursiveArr) {
      visited[vertex] = true;
      recursiveArr[vertex] = true;

      // recursive call to all the adjacent vertices
      for (int i = 0; i < adjList[vertex].size(); i++) {
        // if not already visited
        int adjVertex = adjList[vertex].get(i);
        if (!visited[adjVertex] && isCycleUtil(adjVertex, visited, recursiveArr)) {
          return true;
        } else if (recursiveArr[adjVertex])
          return true;
      }
      // if reached here means cycle has not found in DFS from this vertex
      // reset
      recursiveArr[vertex] = false;
      return false;
    }

  }
http://coddicted.com/detect-cycle-in-a-directed-graph/
http://algorevisited.blogspot.com/2014/11/detecting-cycle-in-directed-graph-dfs.html
Keep track of the vertices already visited by DFS Traversal. While traversing further, if we visit any of the vertex that is already visited then there is a back edge and hence there is cycle in the graph.
public boolean helper(int v, boolean[] visited, Set<Integer> recStack)
{
System.out.println("v: "+v+" set: "+recStack);
//if we have not visited the vertex v yet
//then visit the vertex v and all its adjacent vertices
if(!visited[v])
{
//mark the vertex v to be visited
visited[v] = true;
//add v in the recursion stack
recStack.add(v);
//for all adjacent vertices
for(int i : graph.adj.get(v))
{
//if the adjacent node is not visited yet
if(!visited[i])
{
if(helper(i, visited, recStack))
return true;
}
//if the node is already present on the recursion stack
//then there is cycle add return true
else if(recStack.contains(i))
return true;
}
}
//remove the node from the recursion stack
recStack.remove(v);
return false;
}
I. DFS+Detect Back Edge
To detect a back edge, we can keep track of vertices currently in recursion stack of function for DFS traversal. If we reach a vertex that is already in the recursion stack, then there is a cycle in the tree. The edge that connects current vertex to the vertex in the recursion stack is back edge. We have used recStack[] array to keep track of vertices in the recursion stack.

Depth First Traversal can be used to detect cycle in a Graph. DFS for a connected graph produces a tree. There is a cycle in a graph only if there is a back edge present in the graph. A back edge is an edge that is from a node to itself (selfloop) or one of its ancestor in the tree produced by DFS.
bool Graph::isCyclicUtil(int v, bool visited[], bool *recStack)
{
    if(visited[v] == false)
    {
        // Mark the current node as visited and part of recursion stack
        visited[v] = true;
        recStack[v] = true;
        // Recur for all the vertices adjacent to this vertex
        list<int>::iterator i;
        for(i = adj[v].begin(); i != adj[v].end(); ++i)
        {
            if ( !visited[*i] && isCyclicUtil(*i, visited, recStack) )
                return true;
            else if (recStack[*i])
                return true;
        }
    }
    recStack[v] = false// remove the vertex from recursion stack
    return false;
}
// Returns true if the graph contains a cycle, else false.
// This function is a variation of DFS() in http://www.geeksforgeeks.org/archives/18212
bool Graph::isCyclic()
{
    // Mark all the vertices as not visited and not part of recursion
    // stack
    bool *visited = new bool[V];
    bool *recStack = new bool[V];
    for(int i = 0; i < V; i++)
    {
        visited[i] = false;
        recStack[i] = false;
    }
    // Call the recursive helper function to detect cycle in different
    // DFS trees
    for(int i = 0; i < V; i++)
        if (isCyclicUtil(i, visited, recStack))
            return true;
    return false;
}
Java code:http://algs4.cs.princeton.edu/42directed/DirectedCycle.java.html
http://algorevisited.blogspot.com/2014/11/detecting-cycle-in-directed-graph-dfs.html
When marked/visited[v] is true, the node may be not in current path(stack). This is why we use a different onStack array, and set it and uncheck it later in each recursive call.
   public DirectedCycle(Digraph G) {
        marked  = new boolean[G.V()];
        onStack = new boolean[G.V()];
        edgeTo  = new int[G.V()];
        for (int v = 0; v < G.V(); v++)
            if (!marked[v]) dfs(G, v);
    }

    // check that algorithm computes either the topological order or finds a directed cycle
    private void dfs(Digraph G, int v) {
        onStack[v] = true;
        marked[v] = true;
        for (int w : G.adj(v)) {

            // short circuit if directed cycle found
            if (cycle != null) return;

            //found new vertex, so recur
            else if (!marked[w]) {
                edgeTo[w] = v;
                dfs(G, w);
            }

            // trace back directed cycle
            else if (onStack[w]) {
                cycle = new Stack<Integer>();
                for (int x = v; x != w; x = edgeTo[x]) {
                    cycle.push(x);
                }
                cycle.push(w);
                cycle.push(v);
            }
        }

        onStack[v] = false;
    }
BFS
Why DFS and not BFS for finding cycle in graphs
Depth first search is more memory efficient than breadth first search as you can backtrack sooner.
Once DFS finds a cycle, the stack will contain the nodes forming the cycle. The same is not true for BFS, so you need to do extra work if you want to also print the found cycle.
Also if your graph is directed then you have to not just remember if you have visited a node or not, but also how you got there.

http://stackoverflow.com/questions/4464336/pseudocode-to-find-cycles-in-a-graph-using-breadth-first-search
n an undirected graph, it's a traditional BFS that aborts and reports a cycle found when it reaches a node previously marked as visited. You can find pseudocode for BFS here.


In a directed graph, it gets trickier, since you have to remember which way were you walking when you reached the node, and the spatial complexity disadvantage over DFS gets even worse.

From http://algorithmsandme.blogspot.com/2014/06/graphs-detecting-cycle-in-undirected.html
Second Method Using disjoint sets
int detect_cycle(Node * graph[]){
        int rep[NUM_NODE + 1] ;
        int i;
        make_set(rep);
        for(i=1; i<= NUM_NODE; i++){
                Node * u =  graph[i];
                if(u){
                        Node *v = u->next;
                        while(v){
                                int x = find(rep, u->value);
                                int y = find(rep, v->value);

                                if(x == y) return true;

                                union_1(rep, x,y);
                                v = v->next;
                        }
                }
        }
        return 0;
}

DFS, Using Stack: http://www.sanfoundry.com/java-program-check-cycle-graph-using-graph-traversal/
http://algs4.cs.princeton.edu/42directed/DirectedCycle.java.html
II. Topological sort+BFS: Use Zero Indegree
X. Topological Sorting
Time Complexity : O(V+E)
The idea is to simply use Kahn’s algorithm for Topological Sorting
Steps involved in detecting cycle in a directed graph using BFS.
Step-1: Compute in-degree (number of incoming edges) for each of the vertex present in the graph and initialize the count of visited nodes as 0.
Step-2: Pick all the vertices with in-degree as 0 and add them into a queue (Enqueue operation)
Step-3: Remove a vertex from the queue (Dequeue operation) and then.
  1. Increment count of visited nodes by 1.
  2. Decrease in-degree by 1 for all its neighboring nodes.
  3. If in-degree of a neighboring nodes is reduced to zero, then add it to the queue.
Step 4: Repeat Step 3 until the queue is empty.
Step 5: If count of visited nodes is not equal to the number of nodes in the graph has cycle, otherwise not.
How to find in-degree of each node?
There are 2 ways to calculate in-degree of every vertex:
Take an in-degree array which will keep track of
1) Traverse the array of edges and simply increase the counter of the destination node by 1.
for each node in Nodes
    indegree[node] = 0;
for each edge(src,dest) in Edges
    indegree[dest]++
Time Complexity: O(V+E)
2) Traverse the list for every node and then increment the in-degree of all the nodes connected to it by 1.
    for each node in Nodes
        If (list[node].size()!=0) then
        for each dest in list
            indegree[dest]++;
Time Complexity: The outer for loop will be executed V number of times and the inner for loop will be executed E number of times, Thus overall time complexity is O(V+E).

https://tekjutsu.wordpress.com/2010/02/03/3/
we start by calculating the starting inDegree for each Vertex. Each Vertex with inDegree == 0 is put into a queue. These Vertices are starting points for processing. We begin the search from a Vertex in the queue, following the Edges and keeping a count of the Vertices visited. We decrement the inDegree of Vertices as their in-bound Edges are processed. Vertices whose inDegree goes to zero are put into the queue. When we reach the end of a branch where there are no more out-bound Edges, we take another Vertex from the queue and traverse. If we empty the queue before we’ve visited all the Vertices then we’ve found a cycle.
public class Vertex {
   public String name;
   public List<Edge> outEdges; // The out-bound Edges of this Vertex
   public int inDegree; // A convenient *scratch variable* for our algorithm to 
}
public static boolean hasCycle(DirectedGraph graph){
   if (graph == null || graph.size() == 0) return false;
   Collection <Vertex>vertexCollect = graph.vertices();
   Queue <Vertex> q; // Queue will store vertices that have in-degree of zero
   long counter = 0;
   /* Calculate the in-degree of all vertices and store on the Vertex */
   for (Vertex v: vertexCollect)
      v.inDegree = 0;
   for (Vertex v: vertexCollect){
      for(Edge edge : v.outEdges())
         edge.dest().inDegree++;
      }
   /* Find all vertices with in-degree == 0 and put in queue */
   q = new LinkedList<Vertex>();
   for (Vertex v : vertexCollect){
      if (v.inDegree == 0)
         q.offer(v);
   }
   if(q.size() == 0){
   return true; // Cycle found – all vertices have in-bound edges
   /* Traverse the queue counting Vertices visited */
   for (counter = 0; !q.isEmpty(); counter++) {
      Vertex v=q.poll();
      for (Edge e: v.outEdges()){
         Vertex w = e.dest();
         if(–w.inDegree == 0){
            q.offer(w);
         }
      }
   }
   if (counter != vertexCollect.size() ){
      return true;  //Cycle found
   }
   return false;
}
Floyd’s Algorithm – Tortoise and Hare
https://tekjutsu.wordpress.com/2010/03/04/floyds-algorithm-tortoise-and-hare/
 In the prevous post the idea is to eliminate all vertices and edges that are not part of cycles so that what’s left is a cycle or cycles. Floyd’s algorithm finds cycles directly – it recognizes that it’s traversing a cycle. This has the advantage of allowing us to get the cycle length. Previously we could have easily totaled the vertices remaining in the cycles but since we never traversed the cycles we didn’t know how many cycles there were or their lengths.

Another characteristic of Floyd’s algorithm is that it is well suited for space complexity since it stores only two pointers that move through the graph. One pointer, the hare, moves twice as fast as the other, the tortoise, and if the two meet we know they’re in a cycle.

Floyd’s algorithm finds cycles directly – it recognizes that it’s traversing a cycle. This has the advantage of allowing us to get the cycle length.
Not really good for graph - usually used to detect cycle in linkedlist.
public static void findCycleInfo(Set vertices, Vertex startVertex){
   Vertex tortoise = startVertex;   //vertex zero
   Vertex hare = startVertex;       //vertex zero
   while (true){
      if (hare.outEdge() == null){
         System.out.println(“No cycle”);
         break;
      }else hare = hare.outEdge().dest();   //Advance hare a step
      if (hare.outEdge() == null){
         System.out.println(“No cycle”);
         break;
      }else hare = hare.outEdge().dest();   //Advance hare another step
      tortoise = tortoise.outEdge().dest(); //Advance tortoise one step
      if (tortoise == hare){                //Compare identity
         System.out.println(“Cycle found”);
         break;
      }
   }
}

X.
https://algorithms.tutorialhorizon.com/graph-detect-cycle-in-a-directed-graph-using-colors/
We will assign every vertex a color and will use 3 colors- white, gray and black.
  • White Color: Vertices which are not processed will be assigned white colors. So at the beginning all the vertices will be white.
  • Gray Color: Vertices will are currently being processed. If DFS(Depth-First Search) is started from a particular vertex will be in gray color till DFS is not completed (means all the descendants in DFS are not processed.)
  • Black Color: Vertices for which the DFS is completed, means all the processed vertices will be assigned black color.
  • Cycle Detection: During DFS if we encounter a vertex which is already in Gray color (means this vertex already in processing and in Gray color in the current DFS) then we have detected a Cycle and edge from current vertex to gray vertex will a back edge.
  • Example – Graph 2->3->4->2. Start DFS from vertex 2 (make it gray). Then vertex 3 and 4 will be in processing (Gray color) and when 4->2 will be in processing, vertex 2 needs to be colored in gray but vertex 2 is already in gray color, means cycle is detected.
        public boolean isCycle() {
            //Create color sets
            HashSet<Integer> whiteSet = new HashSet<>();
            HashSet<Integer> graySet = new HashSet<>();
            HashSet<Integer> blackSet = new HashSet<>();

            //Initially put all vertices in White set
            for (int i = 0; i <adjList.length ; i++) {
                whiteSet.add(i);
            }
            //traverse only white vertices
            for (int i = 0; i <vertices ; i++) {
                if(whiteSet.contains(i) &&
                        isCycleUtil(i,whiteSet,graySet,blackSet)){
                    return true;
                }
            }
            return false;
        }
        public boolean isCycleUtil(int vertex, HashSet<Integer> whiteSet, HashSet<Integer> graySet, HashSet<Integer> blackSet){
            //visiting this vertex, make it gray from white
            whiteSet.remove(vertex);
            graySet.add(vertex);

            //visit neighbors
            for (int i = 0; i <adjList[vertex].size() ; i++) {
                int adjVertex = adjList[vertex].get(i);

                //check if this vertex is present in gray set, means cycle is found
                if (graySet.contains(adjVertex))
                    return true;

                //check if this vertex is present in black set, means this vertex is already done
                if (blackSet.contains(adjVertex))
                    continue;

                //do traversal from this vertex
                if (isCycleUtil(adjVertex, whiteSet, graySet, blackSet))
                    return true;
            }
            //if here means cycle is not found from this vertex, make if black from gray
            graySet.remove(vertex);
            blackSet.add(vertex);
            return false;
        }
http://www.geeksforgeeks.org/detect-cycle-direct-graph-using-colors/
from CLRS book. The idea is to do DFS of given graph and while doing traversal, assign one of the below three colors to every vertex. O(V+E)
WHITE : Vertex is not processed yet.  Initially
        all vertices are WHITE.

GRAY : Vertex is being processed (DFS for this 
       vertex has started, but not finished which means
       that all descendants (ind DFS tree) of this vertex
       are not processed yet (or this vertex is in function
       call stack)

BLACK : Vertex and all its descendants are 
        processed.

While doing DFS, if we encounter an edge from current 
vertex to a GRAY vertex, then this edge is back edge 
and hence there is a cycle.
// Recursive function to find if there is back edge
// in DFS subtree tree rooted with 'u'
bool Graph::DFSUtil(int u, int color[])
{
    // GRAY :  This vertex is being processed (DFS
    //         for this vertex has started, but not
    //         ended (or this vertex is in function
    //         call stack)
    color[u] = GRAY;
    // Iterate through all adjacent vertices
    list<int>::iterator i;
    for (i = adj[u].begin(); i != adj[u].end(); ++i)
    {
        int v = *i;  // An adjacent of u
        // If there is
        if (color[v] == GRAY)
          return true;
        // If v is not processed and there is a back
        // edge in subtree rooted with v
        if (color[v] == WHITE && DFSUtil(v, color))
          return true;
    }
    // Mark this vertex as processed
    color[u] = BLACK;
    return false;
}
// Returns true if there is a cycle in graph
bool Graph::isCyclic()
{
    // Initialize color of all vertices as WHITE
    int *color = new int[V];
    for (int i = 0; i < V; i++)
        color[i] = WHITE;
    // Do a DFS traversal beginning with all
    // vertices
    for (int i = 0; i < V; i++)
        if (color[i] == WHITE)
           if (DFSUtil(i, color) == true)
              return true;
    return false;
}
https://moonstonelin.wordpress.com/2016/06/06/detect-cycle-in-a-directed-graph/
    public bool HasCycleInDirectedGraph<T>(Graph<T> graph)
    {
        if ((graph == null) || (graph.Nodes.Count <= 1))
        {
            return false;
        }
        HashSet<Node<T>> whiteSet = new HashSet<Node<T>>();
        HashSet<Node<T>> graySet = new HashSet<Node<T>>();
        HashSet<Node<T>> blackSet = new HashSet<Node<T>>();
        foreach (var node in graph.Nodes)
        {
            whiteSet.Add(node);
        }
        foreach (var node in graph.Nodes)
        {
            if (whiteSet.Contains(node))
            {
                bool b = HasCycleInDirectedGraphHelper(node, whiteSet, graySet, whiteSet);
                if (b)
                {
                    return true;
                }
            }
        }
        return false;
    }
    private bool HasCycleInDirectedGraphHelper<T>(Node<T> node, HashSet<Node<T>> whiteSet, HashSet<Node<T>> graySet, HashSet<Node<T>> blackSet)
    {
        whiteSet.Remove(node);
        graySet.Add(node);
        foreach (var neighbor in node.Neighbors)
        {
            if (graySet.Contains(neighbor))
            {
                return true;
            }
            if (whiteSet.Contains(neighbor))
            {
                bool b = HasCycleInDirectedGraphHelper(neighbor, whiteSet, graySet, blackSet);
                if (b)
                {
                    return true;
                }
            }
        }
        graySet.Remove(node);
        blackSet.Add(node);
        return false;
    }
Read full article from Detect Cycle in a Directed Graph | GeeksforGeeks

Labels

LeetCode (1432) GeeksforGeeks (1122) LeetCode - Review (1067) Review (882) Algorithm (668) to-do (609) Classic Algorithm (270) Google Interview (237) Classic Interview (222) Dynamic Programming (220) DP (186) Bit Algorithms (145) POJ (141) Math (137) Tree (132) LeetCode - Phone (129) EPI (122) Cracking Coding Interview (119) DFS (115) Difficult Algorithm (115) Lintcode (115) Different Solutions (110) Smart Algorithm (104) Binary Search (96) BFS (91) HackerRank (90) Binary Tree (86) Hard (79) Two Pointers (78) Stack (76) Company-Facebook (75) BST (72) Graph Algorithm (72) Time Complexity (69) Greedy Algorithm (68) Interval (63) Company - Google (62) Geometry Algorithm (61) Interview Corner (61) LeetCode - Extended (61) Union-Find (60) Trie (58) Advanced Data Structure (56) List (56) Priority Queue (53) Codility (52) ComProGuide (50) LeetCode Hard (50) Matrix (50) Bisection (48) Segment Tree (48) Sliding Window (48) USACO (46) Space Optimization (45) Company-Airbnb (41) Greedy (41) Mathematical Algorithm (41) Tree - Post-Order (41) ACM-ICPC (40) Algorithm Interview (40) Data Structure Design (40) Graph (40) Backtracking (39) Data Structure (39) Jobdu (39) Random (39) Codeforces (38) Knapsack (38) LeetCode - DP (38) Recursive Algorithm (38) String Algorithm (38) TopCoder (38) Sort (37) Introduction to Algorithms (36) Pre-Sort (36) Beauty of Programming (35) Must Known (34) Binary Search Tree (33) Follow Up (33) prismoskills (33) Palindrome (32) Permutation (31) Array (30) Google Code Jam (30) HDU (30) Array O(N) (29) Logic Thinking (29) Monotonic Stack (29) Puzzles (29) Code - Detail (27) Company-Zenefits (27) Microsoft 100 - July (27) Queue (27) Binary Indexed Trees (26) TreeMap (26) to-do-must (26) 1point3acres (25) GeeksQuiz (25) Merge Sort (25) Reverse Thinking (25) hihocoder (25) Company - LinkedIn (24) Hash (24) High Frequency (24) Summary (24) Divide and Conquer (23) Proof (23) Game Theory (22) Topological Sort (22) Lintcode - Review (21) Tree - Modification (21) Algorithm Game (20) CareerCup (20) Company - Twitter (20) DFS + Review (20) DP - Relation (20) Brain Teaser (19) DP - Tree (19) Left and Right Array (19) O(N) (19) Sweep Line (19) UVA (19) DP - Bit Masking (18) LeetCode - Thinking (18) KMP (17) LeetCode - TODO (17) Probabilities (17) Simulation (17) String Search (17) Codercareer (16) Company-Uber (16) Iterator (16) Number (16) O(1) Space (16) Shortest Path (16) itint5 (16) DFS+Cache (15) Dijkstra (15) Euclidean GCD (15) Heap (15) LeetCode - Hard (15) Majority (15) Number Theory (15) Rolling Hash (15) Tree Traversal (15) Brute Force (14) Bucket Sort (14) DP - Knapsack (14) DP - Probability (14) Difficult (14) Fast Power Algorithm (14) Pattern (14) Prefix Sum (14) TreeSet (14) Algorithm Videos (13) Amazon Interview (13) Basic Algorithm (13) Codechef (13) Combination (13) Computational Geometry (13) DP - Digit (13) LCA (13) LeetCode - DFS (13) Linked List (13) Long Increasing Sequence(LIS) (13) Math-Divisible (13) Reservoir Sampling (13) mitbbs (13) Algorithm - How To (12) Company - Microsoft (12) DP - Interval (12) DP - Multiple Relation (12) DP - Relation Optimization (12) LeetCode - Classic (12) Level Order Traversal (12) Prime (12) Pruning (12) Reconstruct Tree (12) Thinking (12) X Sum (12) AOJ (11) Bit Mask (11) Company-Snapchat (11) DP - Space Optimization (11) Dequeue (11) Graph DFS (11) MinMax (11) Miscs (11) Princeton (11) Quick Sort (11) Stack - Tree (11) 尺取法 (11) 挑战程序设计竞赛 (11) Coin Change (10) DFS+Backtracking (10) Facebook Hacker Cup (10) Fast Slow Pointers (10) HackerRank Easy (10) Interval Tree (10) Limited Range (10) Matrix - Traverse (10) Monotone Queue (10) SPOJ (10) Starting Point (10) States (10) Stock (10) Theory (10) Tutorialhorizon (10) Kadane - Extended (9) Mathblog (9) Max-Min Flow (9) Maze (9) Median (9) O(32N) (9) Quick Select (9) Stack Overflow (9) System Design (9) Tree - Conversion (9) Use XOR (9) Book Notes (8) Company-Amazon (8) DFS+BFS (8) DP - States (8) Expression (8) Longest Common Subsequence(LCS) (8) One Pass (8) Quadtrees (8) Traversal Once (8) Trie - Suffix (8) 穷竭搜索 (8) Algorithm Problem List (7) All Sub (7) Catalan Number (7) Cycle (7) DP - Cases (7) Facebook Interview (7) Fibonacci Numbers (7) Flood fill (7) Game Nim (7) Graph BFS (7) HackerRank Difficult (7) Hackerearth (7) Inversion (7) Kadane’s Algorithm (7) Manacher (7) Morris Traversal (7) Multiple Data Structures (7) Normalized Key (7) O(XN) (7) Radix Sort (7) Recursion (7) Sampling (7) Suffix Array (7) Tech-Queries (7) Tree - Serialization (7) Tree DP (7) Trie - Bit (7) 蓝桥杯 (7) Algorithm - Brain Teaser (6) BFS - Priority Queue (6) BFS - Unusual (6) Classic Data Structure Impl (6) DP - 2D (6) DP - Monotone Queue (6) DP - Unusual (6) DP-Space Optimization (6) Dutch Flag (6) How To (6) Interviewstreet (6) Knapsack - MultiplePack (6) Local MinMax (6) MST (6) Minimum Spanning Tree (6) Number - Reach (6) Parentheses (6) Pre-Sum (6) Probability (6) Programming Pearls (6) Rabin-Karp (6) Reverse (6) Scan from right (6) Schedule (6) Stream (6) Subset Sum (6) TSP (6) Xpost (6) n00tc0d3r (6) reddit (6) AI (5) Abbreviation (5) Anagram (5) Art Of Programming-July (5) Assumption (5) Bellman Ford (5) Big Data (5) Code - Solid (5) Code Kata (5) Codility-lessons (5) Coding (5) Company - WMware (5) Convex Hull (5) Crazyforcode (5) DFS - Multiple (5) DFS+DP (5) DP - Multi-Dimension (5) DP-Multiple Relation (5) Eulerian Cycle (5) Graph - Unusual (5) Graph Cycle (5) Hash Strategy (5) Immutability (5) Java (5) LogN (5) Manhattan Distance (5) Matrix Chain Multiplication (5) N Queens (5) Pre-Sort: Index (5) Quick Partition (5) Quora (5) Randomized Algorithms (5) Resources (5) Robot (5) SPFA(Shortest Path Faster Algorithm) (5) Shuffle (5) Sieve of Eratosthenes (5) Strongly Connected Components (5) Subarray Sum (5) Sudoku (5) Suffix Tree (5) Swap (5) Threaded (5) Tree - Creation (5) Warshall Floyd (5) Word Search (5) jiuzhang (5)

Popular Posts