Graph Theory Calculator
Calculate properties of graphs including degree, adjacency matrix, and shortest paths. Enter values for instant results with step-by-step formulas.
Formula
Sum of degrees = 2|E|
The Handshaking Lemma states that the sum of all vertex degrees equals twice the number of edges, because each edge contributes 1 to the degree of each of its two endpoints. This fundamental identity constrains the possible degree sequences of any graph.
Worked Examples
Example 1: Analyzing a Small Network
Problem: Analyze the graph with 5 vertices and edges: 0-1, 0-2, 1-2, 1-3, 2-3, 3-4.
Solution: Adjacency matrix built from 6 edges.\nDegrees: v0=2, v1=3, v2=3, v3=3, v4=1\nSum of degrees = 12 = 2 * 6 edges (handshaking lemma verified)\nBFS from v0: distances = [0, 1, 1, 2, 3]\nDiameter = 3 (path 0->1->3->4 or 0->2->3->4)\nDensity = 6/10 = 60%\nOdd-degree vertices: 4 (v1, v2, v3, v4) => No Euler path
Result: Connected graph, 6 edges, diameter 3, density 60%, not Eulerian, not bipartite
Example 2: Bipartite Graph Check
Problem: Is the graph with 4 vertices and edges 0-1, 0-3, 1-2, 2-3 bipartite?
Solution: BFS coloring: v0=Red, v1=Blue, v3=Blue, v2=Red (from v1), v3 already Blue (from v2=Red, consistent)\nPartition: Red={0,2}, Blue={1,3}\nAll edges cross between partitions.\nThis is a 4-cycle (C4), which is bipartite.
Result: The graph IS bipartite with partition {0,2} and {1,3}. It is a cycle of even length.
Frequently Asked Questions
What is graph theory and what are its basic concepts?
Graph theory is a branch of discrete mathematics that studies relationships between objects using vertices (nodes) and edges (connections). A graph G = (V, E) consists of a set of vertices V and a set of edges E, where each edge connects two vertices. Graphs can be undirected (edges have no direction) or directed (edges point from one vertex to another). They can be weighted (edges have numerical values) or unweighted. Graph theory was founded by Leonhard Euler in 1736 when he solved the famous Konigsberg Bridge Problem. Today, graph theory is essential in computer networking, social media analysis, transportation planning, circuit design, and bioinformatics, making it one of the most widely applied areas of mathematics.
What does it mean for a graph to be connected?
An undirected graph is connected if there exists a path between every pair of vertices. If the graph is not connected, it consists of multiple connected components, which are maximal connected subgraphs. A directed graph is strongly connected if there is a directed path from every vertex to every other vertex. It is weakly connected if the underlying undirected graph (ignoring edge directions) is connected. Connectivity can be tested in O(V + E) time using BFS or DFS from any vertex. The number of connected components is found by counting how many times you need to restart the search. In network reliability analysis, vertex connectivity (minimum vertices to remove to disconnect) and edge connectivity (minimum edges to remove) measure how robust a network is against failures.
What is the diameter of a graph?
The diameter of a connected graph is the longest shortest path between any pair of vertices, representing the maximum distance any two vertices can be from each other. It measures the worst-case communication delay or travel time in a network. For example, the diameter of the internet graph determines the maximum number of hops a packet might need to reach any destination. To compute the diameter, you find the shortest path between all pairs of vertices and take the maximum. For unweighted graphs, this can be done by running BFS from every vertex, taking O(V * (V + E)) time. In social networks, the small world phenomenon suggests that most real-world networks have surprisingly small diameters relative to their size, typically around 6 (six degrees of separation).
What is graph density and what does it tell you?
Graph density is the ratio of actual edges to the maximum possible number of edges. For an undirected graph with n vertices, the maximum number of edges is n(n-1)/2, so density = 2|E| / (n(n-1)). For a directed graph, the maximum is n(n-1), so density = |E| / (n(n-1)). Density ranges from 0 (no edges) to 1 (complete graph). Sparse graphs (density near 0) have few edges relative to vertices and are common in real-world networks like road maps, social networks, and the internet. Dense graphs (density near 1) have many edges and arise in clique-like structures. The density of a graph affects algorithm choice: adjacency lists are efficient for sparse graphs while adjacency matrices work well for dense graphs.
What is a bipartite graph and how do you detect one?
A bipartite graph is a graph whose vertices can be divided into two disjoint sets such that every edge connects a vertex in one set to a vertex in the other set (no edges within the same set). Equivalently, a graph is bipartite if and only if it contains no odd-length cycles, which is the same as being 2-colorable. Bipartiteness can be tested in O(V + E) time using BFS: assign colors alternately as you traverse the graph, and if you ever try to assign a color that conflicts with an existing color, the graph is not bipartite. Bipartite graphs model many natural situations: job assignments (workers and tasks), course scheduling (students and courses), and matching problems. The maximum matching in a bipartite graph can be found efficiently using the Hungarian algorithm or Hopcroft-Karp algorithm.
How is graph theory applied in social network analysis?
Social network analysis uses graph theory extensively to understand relationships and influence patterns. Each person is a vertex and each relationship (friendship, follow, message) is an edge. Degree centrality identifies popular or well-connected individuals. Betweenness centrality finds people who serve as bridges between groups. PageRank (used by Google) measures importance based on the structure of incoming links. Community detection algorithms find clusters of closely connected people. The clustering coefficient measures how much your friends are also friends with each other. Shortest paths reveal the degrees of separation between individuals. Graph theory also powers recommendation engines (friend suggestions, content recommendations) and helps detect fraud, identify influencers, analyze information spread, and model epidemic propagation through social contact networks.