Graph Theory Calculator

Enter a finite simple graph to calculate its order, size, vertex degrees, density, components, connectivity, cycles, and structural properties. Analyze undirected graphs or directed graphs entirely in your browser.

Enter a graph

Self-loops are not allowed; repeated edges are counted once.
Separate labels with commas, semicolons, or new lines.5 listed

Use A,B for an undirected edge.4 edges

Private by design: vertex and edge data is parsed and analyzed on this device. It is not uploaded, saved, or included in the page URL.

Graph analysis

The sample graph is analyzed below.

Advertisement

Graph formulas

Order and size

n = |V|,   m = |E|

The order is the vertex count; the size is the edge count.

Undirected degree sum

Σ deg(v) = 2m

Every undirected edge contributes one to the degree of both endpoints.

Directed degree sums

Σ in(v) = Σ out(v) = m

Every directed edge contributes one incoming and one outgoing incidence.

Undirected density

D = 2m / [n(n − 1)]

The edge count divided by the maximum n(n − 1)/2 for a simple graph.

Directed density

D = m / [n(n − 1)]

The arc count divided by the maximum number of ordered pairs without loops.

Tree edge count

m = n − 1

A connected simple undirected graph is a tree exactly when it has n − 1 edges.

Properties reported by the calculator

Connected components partition an undirected graph into maximal connected parts. In directed mode, weak components ignore arrow direction, while strongly connected components require a directed path both ways between every pair in a component.

Complete means every permitted pair is joined. Regular means all undirected degrees are equal; directed mode reports degree-balanced regular only when every vertex has the same in-degree and the same out-degree. Bipartite means the vertices can be split into two groups with no edge inside either group; direction is ignored for this test.

A tree is a nonempty connected acyclic undirected graph. A forest is an acyclic undirected graph and may have several components. A directed graph is reported as a DAG when it has no directed cycle.

Euler properties concern using every edge exactly once, not visiting every vertex once. For directed graphs, an Euler circuit requires balanced in- and out-degrees on every edge-bearing vertex; an open Euler trail requires one start vertex with one extra outgoing edge and one end vertex with one extra incoming edge. Edge-bearing vertices must also lie in one weak component.

Worked graph example

For V = {A, B, C, D, E} and E = {{A,B}, {B,C}, {C,A}, {C,D}}, the graph has order 5 and size 4. Its degrees are 2, 2, 3, 1, 0, so the sorted degree sequence is (3, 2, 2, 1, 0).

CheckResultReason
Degree sum82m = 2 × 4 = 8
Density40%2 × 4 / (5 × 4) = 0.4
Components2{A,B,C,D} and isolated vertex {E}
CycleYesA–B–C–A is a cycle.
BipartiteNoThe three-cycle has odd length.

Input rules, method, and limits

Vertex labels are case-sensitive text. Separate the optional vertex list with commas, semicolons, or line breaks. Edge endpoints are automatically added to the graph, but isolated vertices must be listed explicitly. Each edge must occupy one line and contain exactly two labels separated by a comma. Directed input may instead use A -> B; the first endpoint is the source and the second is the destination.

This calculator analyzes finite simple graphs and digraphs. It rejects self-loops. Repeated undirected edges—including reversed repetitions such as A,B and B,A—are collapsed to one edge. Directed reciprocal edges are distinct, while exact repeated arcs are collapsed. Whitespace surrounding labels is ignored, but spaces inside labels are retained.

Connectivity, component, bipartite, and cycle checks use adjacency-list searches. Directed strong components are found with two depth-first passes. Results are limited to 200 vertices, 10,000 unique edges, 20,000 vertex-input characters, and 50,000 edge-input characters so an accidental extreme input does not freeze the page. Density is displayed as 0% when fewer than two vertices exist because no distinct vertex pair is available.

The simple-graph definition, degree-sum theorem, complete-graph edge formula, tree criterion, and undirected Euler conditions follow OpenStax, Contemporary Mathematics, Chapter 12 key concepts and its formula review.

Calculation note: formulas, graph-mode distinctions, validation behavior, and representative outputs checked by the Starlight Tools editorial team. Last reviewed: .

Graph theory calculator FAQ

How do I enter a graph?

List vertices with commas, semicolons, or line breaks. Then enter one edge per line with a comma between endpoints. For example, A,B joins A and B. In directed mode it means A → B. You may also type A -> B in directed mode.

Do I have to list every vertex?

No. Edge endpoints are added automatically. You only need the vertex list for isolated vertices or when you want to define a graph with no edges.

Can I enter loops or parallel edges?

This tool analyzes simple graphs, so a self-loop such as A,A is rejected. Repeated edges are ignored after the first occurrence. In directed mode, A → B and B → A are different edges.

What is the difference between degree, in-degree, and out-degree?

Undirected degree counts edges touching a vertex. In a directed graph, in-degree counts arrows entering the vertex and out-degree counts arrows leaving it. Their sum is the vertex’s total degree.

What does graph density measure?

Density compares the actual edge count with the largest possible edge count for the same number of vertices. It ranges from 0% for no edges to 100% for a complete simple graph or complete simple digraph.

When is a graph connected?

An undirected graph is connected when every vertex can be reached from every other vertex. A directed graph is weakly connected when this is true after arrow directions are ignored and strongly connected when directed paths exist both ways between every pair.

How is an Euler trail different from a Hamilton path?

An Euler trail uses every edge exactly once. A Hamilton path visits every vertex exactly once. This calculator checks degree-based Euler conditions; it does not test for Hamilton paths or cycles.

Does the calculator store my graph?

No. Parsing, graph searches, copying, and CSV creation run locally in your browser. The tool does not transmit or save entered vertices or edges.

Explore more tools