User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Adjacency List
Result will appear here…
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

Graph representation matters. An edge list is compact for storage but inefficient for traversal - scanning all edges to find neighbors of a single vertex costs O(E) per query. An adjacency list reduces that to O(1) lookup plus O(deg(v)) iteration. This converter parses edge pairs, deduplicates repeated connections, and outputs a zero-indexed adjacency array. It handles both directed and undirected interpretations. Feed it raw edge data in any common format and get a structure ready for BFS, DFS, Dijkstra, or any standard graph algorithm.

The tool accepts flexible input: JSON bracket notation like [0, 1], space-separated pairs, comma-separated pairs, or arrow syntax 0 β†’ 1. Vertices are assumed integer-indexed starting at 0. If your graph has isolated vertices beyond the maximum index found in edges, specify the vertex count manually. Note: this tool does not handle weighted edges or hypergraphs. For multigraph input, parallel edges are collapsed into single adjacency entries.

adjacency list edge list graph converter graph theory data structure adjacency representation graph algorithms

Formulas

Given an edge list E = {(u1, v1), (u2, v2), …, (um, vm)} over vertex set V = {0, 1, …, n βˆ’ 1}, the adjacency list Adj is constructed as follows:

For each vertex v ∈ V:
Adj[v] = {w | (v, w) ∈ E}

For an undirected graph, every edge (u, v) implies both w ∈ Adj[u] and u ∈ Adj[v]. For a directed graph, only the forward direction is recorded. The degree of vertex v equals the length of its adjacency list:

deg(v) = |Adj[v]|

Total construction time is O(V + E) using hash sets for deduplication. The total space consumed is O(V + 2E) for undirected and O(V + E) for directed graphs.

Where: V = set of vertices, E = set of edges, n = number of vertices, m = number of edges, Adj[v] = neighbor set of vertex v, deg(v) = degree of vertex v.

Reference Data

RepresentationSpace ComplexityAdd EdgeQuery NeighborsCheck Edge ExistsBest For
Edge ListO(E)O(1)O(E)O(E)Storage, Kruskal’s MST
Adjacency ListO(V + E)O(1)O(deg(v))O(deg(v))BFS, DFS, most algorithms
Adjacency MatrixO(V2)O(1)O(V)O(1)Dense graphs, Floyd-Warshall
Incidence MatrixO(V β‹… E)O(V)O(E)O(E)Theoretical analysis
Compressed Sparse RowO(V + E)O(V + E)O(deg(v))O(log deg(v))Static graphs, GPU/SIMD
Hash Map of SetsO(V + E)O(1) avgO(deg(v))O(1) avgDynamic graphs, non-integer keys
Edge List (sorted)O(E)O(E)O(log E)O(log E)Binary search queries
Adjacency MultilistO(V + E)O(1)O(deg(v))O(deg(v))Undirected traversal
Forward StarO(V + E)O(V + E)O(deg(v))O(log deg(v))Network flow
Doubly Connected Edge ListO(V + E)O(1)O(deg(v))O(deg(v))Planar subdivisions, computational geometry
Object-Pointer (Node class)O(V + E)O(1)O(deg(v))O(deg(v))OOP implementations, trees

Frequently Asked Questions

Duplicate edges are merged. Internally the converter uses a Set per vertex, so inserting the same neighbor twice has no effect. The output adjacency list will contain each neighbor at most once per vertex, matching the behavior described in the edges-to-adjacency-list npm module specification.
The converter auto-detects the maximum vertex index and creates entries for all vertices from 0 to that maximum, even if they have no edges (they receive empty adjacency arrays). If you have isolated vertices beyond the max index in your edges, use the optional vertex count field to specify the true number of vertices.
In undirected mode, each edge (u, v) adds v to Adj[u] AND u to Adj[v]. In directed mode, only v is added to Adj[u]. Choose directed for DAGs, dependency graphs, or any asymmetric relationship. Choose undirected for social networks, road maps, or symmetric connections.
Four formats are auto-detected: JSON array notation like [0, 1], space-separated pairs like "0 1", comma-separated pairs like "0,1", and arrow notation like "0 -> 1" or "0 β†’ 1". You can mix formats across lines. Each line should contain exactly one edge (two integer vertices). Lines that cannot be parsed are skipped with a warning.
Yes. The algorithm runs in O(V + E) time and uses hash-based Set structures for deduplication. Graphs with tens of thousands of edges convert in under 50ms in modern browsers. The primary bottleneck for extremely large graphs would be rendering the output text, not the conversion itself.
Neighbors are sorted in ascending numerical order for deterministic, reproducible output. This makes it easier to diff results, verify correctness, and use the output in algorithms that assume sorted adjacency (like binary search for edge existence checks). The sorting step adds O(V Β· deg(v) Β· log(deg(v))) but is negligible for typical graph sizes.