Graph Theory Calculator
Calculate properties of graphs including degree, adjacency matrix, and shortest paths. Enter values for instant results with step-by-step formulas.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Graph Theory Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: Sum of degrees = 2|E|
Worked example โ Connected graph, 6 edges, diameter 3, density 60%, not Eulerian, not bipartite
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. Degrees: v0=2, v1=3, v2=3, v3=3, v4=1 Sum of degrees = 12 = 2 * 6 edges (handshaking lemma verified) BFS from v0: distances = [0, 1, 1, 2, 3] Diameter = 3 (path 0->1->3->4 or 0->2->3->4) Density = 6/10 = 60% Odd-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) Partition: Red={0,2}, Blue={1,3} All edges cross between partitions. This 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 is the adjacency matrix and how do you read it?
The adjacency matrix is an n-by-n matrix A where n is the number of vertices, and entry A[i][j] equals 1 if there is an edge from vertex i to vertex j, and 0 otherwise. For undirected graphs, the adjacency matrix is always symmetric because an edge between i and j goes in both directions. The diagonal entries are typically 0 (no self-loops). The sum of entries in row i gives the degree of vertex i. Powers of the adjacency matrix have a remarkable property: the entry (A^k)[i][j] gives the number of walks of length k from vertex i to vertex j. This property is used in network analysis to count paths, compute centrality measures, and study the spectral properties of graphs through eigenvalues of the adjacency matrix.
What is vertex degree and why is the handshaking lemma important?
The degree of a vertex is the number of edges incident to it (connected to it). In directed graphs, each vertex has an in-degree (edges coming in) and an out-degree (edges going out). The Handshaking Lemma states that the sum of all vertex degrees equals twice the number of edges: sum of all degrees = 2|E|. This is because each edge contributes exactly 1 to the degree of each of its two endpoints. A consequence is that the number of vertices with odd degree must be even. For directed graphs, the sum of all in-degrees equals the sum of all out-degrees, which equals the number of edges. Degree analysis reveals important structural properties: vertices with high degree are hubs in networks, and the degree distribution characterizes network types.
What is a shortest path and how is BFS used to find it?
The shortest path between two vertices in a graph is the path with the minimum number of edges (for unweighted graphs) or minimum total weight (for weighted graphs). Breadth-First Search (BFS) finds shortest paths in unweighted graphs by exploring vertices layer by layer, starting from the source vertex. BFS visits all vertices at distance 1 first, then distance 2, and so on. It runs in O(V + E) time where V is vertices and E is edges. For weighted graphs, Dijkstra algorithm finds shortest paths in O((V + E) log V) time using a priority queue. The Floyd-Warshall algorithm finds shortest paths between all pairs of vertices in O(V^3) time. Shortest path algorithms are fundamental to GPS navigation, network routing protocols, and social network analysis.
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 are Eulerian paths and circuits?
An Eulerian path is a path that visits every edge of a graph exactly once. An Eulerian circuit is an Eulerian path that starts and ends at the same vertex. Euler proved that a connected undirected graph has an Eulerian circuit if and only if every vertex has even degree, and it has an Eulerian path (but not a circuit) if and only if exactly two vertices have odd degree. For directed graphs, an Eulerian circuit exists if and only if every vertex has equal in-degree and out-degree. These conditions can be checked in O(V) time after computing degrees. The original Konigsberg Bridge Problem asked whether an Eulerian path existed through the city, and Euler proved it did not because more than two vertices had odd degree. Eulerian paths are used in DNA sequencing, circuit board manufacturing, and snow plow route optimization.
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.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐งฎAnnulus Area Calculator
Calculate annulus area with inputs, formulas, and instant results.
๐งฎArea Calculator
Calculate area with inputs, formulas, and instant results.
๐งฎArea of a Rectangle Calculator
Calculate the area, perimeter, and diagonal of a rectangle. Find missing sides from known area. Convert between metric and imperial area units.
๐งฎArea of Crescent Calculator
Calculate area of crescent with inputs, formulas, and instant results.
๐งฎCenter of Mass Calculator
Calculate center of mass with inputs, formulas, and instant results.
๐งฎCentroid Calculator
Calculate centroid with inputs, formulas, and instant results.
๐งฎChord Length Calculator
Calculate chord length with inputs, formulas, and instant results.
๐งฎConic Sections Calculator
Calculate conic sections with inputs, formulas, and instant results.