Skip to main content

Graph Theory Calculator

Calculate properties of graphs including degree, adjacency matrix, and shortest paths. Enter values for instant results with step-by-step formulas.

Skip to calculator
Mathematics

Graph Theory Calculator

Calculate graph properties including vertex degrees, adjacency matrix, shortest paths, connectivity, diameter, density, and bipartiteness.

Last updated: December 2025Reviewed by NovaCalculator Mathematics Team

Calculator

Adjust values & calculate
Graph Summary
5 vertices, 6 edges
Connected | Density: 60.0%
Diameter
3
Degree Sum
12
Max Edges
10
Bipartite
No
Euler Circuit
No
Euler Path
No
Vertex Degrees
v0
2
v1
3
v2
3
v3
3
v4
1
Shortest Distances from Vertex 0 (BFS)
v0
0
v1
1
v2
1
v3
2
v4
3

Adjacency Matrix

001100
110110
211010
301101
400010
Your Result
5 vertices, 6 edges | Connected | Diameter: 3 | Density: 60.0%
Share Your Result
Understand the Math

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.

Last reviewed: December 2025

Worked Examples

Example 1: Analyzing a Small Network

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

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.
Expert Insights

Background & Theory

The Graph Theory Calculator applies the following established principles and formulas. Mathematics rests on a hierarchy of number systems, each extending the previous. The natural numbers (1, 2, 3, ...) support counting and ordering. The integers add negative values and zero, enabling subtraction without restriction. The rational numbers, expressible as p/q where p and q are integers and q is nonzero, close the system under division. The real numbers fill the gaps left by irrationals such as the square root of 2 or pi, forming a complete ordered field. The complex numbers, written as a + bi where i is the square root of negative one, complete the algebraic closure of the reals and allow every polynomial to have a root. Prime factorization states that every integer greater than one is uniquely expressible as a product of primes, a result known as the Fundamental Theorem of Arithmetic. Computing the greatest common divisor (GCD) of two integers relies most efficiently on the Euclidean algorithm: repeatedly replace the larger number with the remainder when it is divided by the smaller, until the remainder is zero. The last nonzero remainder is the GCD. The least common multiple (LCM) follows from the identity LCM(a, b) = |a * b| / GCD(a, b). Modular arithmetic defines equivalence classes of integers that share the same remainder under division by a modulus n. Fermat's Little Theorem and Euler's Theorem arise from this structure and underpin modern cryptography. Logarithms are the inverses of exponential functions. If b raised to the power x equals y, then the logarithm base b of y equals x. The natural logarithm uses base e, approximately 2.71828. Combinatorics counts arrangements and selections. The number of ordered arrangements (permutations) of r objects from n distinct objects is nPr = n! / (n - r)!. The number of unordered selections (combinations) is nCr = n! / (r! * (n - r)!). Pascal's triangle arranges these binomial coefficients so that each entry equals the sum of the two entries directly above it. The Fibonacci sequence, defined by F(1) = 1, F(2) = 1, and F(n) = F(n-1) + F(n-2), appears throughout nature and connects deeply to the golden ratio via Binet's formula.

History

The history behind the Graph Theory Calculator traces back through the following developments. Mathematics as a systematic discipline traces to ancient Mesopotamia. Babylonian clay tablets dating to around 1800 BCE demonstrate knowledge of quadratic equations, Pythagorean triples, and base-60 arithmetic, suggesting a practical mathematical tradition far preceding Greek formalism. Euclid of Alexandria compiled the Elements around 300 BCE, establishing the axiomatic method that would define rigorous mathematics for over two thousand years. His work organized plane geometry, number theory, and proportion into logically chained propositions derived from a small set of postulates. The algorithm bearing his name for computing GCDs appears in Book VII and remains in use today. In the 9th century, the Persian scholar Muhammad ibn Musa Al-Khwarizmi wrote Al-Kitab al-mukhtasar fi hisab al-jabr wal-muqabala, the treatise whose title gave algebra its name. He systematized the solution of linear and quadratic equations and described procedures that operated on unknowns as objects, a conceptual leap away from purely numerical calculation. Rene Descartes introduced coordinate geometry in 1637 by uniting algebra and Euclidean geometry, allowing curves to be studied through equations. This synthesis set the stage for calculus. Isaac Newton and Gottfried Wilhelm Leibniz independently developed calculus during the 1660s and 1670s, triggering a priority dispute that lasted decades and divided British and Continental mathematicians. Carl Friedrich Gauss proved the Fundamental Theorem of Algebra in 1799, showing that every nonconstant polynomial has at least one complex root. His Disquisitiones Arithmeticae of 1801 established modern number theory. David Hilbert's formalist program at the turn of the 20th century sought to place all of mathematics on an explicit axiomatic foundation, a project that Kurt Godel's incompleteness theorems of 1931 showed to be fundamentally limited. Alan Turing's work in the 1930s on computability introduced the theoretical model of the stored-program computer and linked mathematical logic directly to the limits of algorithmic calculation. His proof that no algorithm can decide in general whether an arbitrary program will halt or run forever placed fundamental boundaries on what mathematics can mechanically determine, and it opened the discipline now known as theoretical computer science.

Share this calculator

Explore More

Frequently Asked Questions

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.
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.
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).
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.
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.
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.
Educational Note: This calculator is provided for educational and informational purposes. Results are based on the formulas and inputs provided. Always verify important calculations independently. NovaCalculator processes calculator inputs client-side; optional analytics follow visitor consent settings.Reviewed by: NovaCalculator Mathematics Team โ€” Verified against standard mathematical and scientific references. Last reviewed: December 2025. ยฉ 2024โ€“2026 NovaCalculator.

Share this calculator

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.

References

Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy