background preloader

Graph theory

Facebook Twitter

Floyd-Warshall All-Pairs Shortest Pairs Algorithm. A (Very) Brief Introduction to Graphs Graphs are a very important data structure in computer science. Many otherwise very difficult problems can be expressed in terms of a graph and solved using standard graph searching/manipulation algorithms. Graphs can be simply viewed as a set of vertices/nodes and edges connecting these vertices.

Mathematically G = (V,E), if u and v are elements of V, then an edge can be denoted as (u,v). Graphs can be basically classified as either being undirected or directed. In the former, the edges do not have a direction i.e. The adjacency matrix that represents the above graph is: NB: inf. Shortest Paths It is also possible that the edges in a graph may bear weights, these may be positive, negative, or zero.

All-Pairs-Shortest-Path Algorithms The problem of finding the shortest path between all pairs of vertices on a graph is akin to making a table of all of the distances between all pairs of cities on a road map. Constructing The Shortest Path Conclusion. Minimum Spanning Tree Problem: Kruskal's Algorithm. Max-Flow Problem: Ford-Fulkerson Algorithm. Minimum Spanning Tree Problem: Prim's Algorithm. Dijkstra's Shortest Path Algorithm.