← Course home

Python reference · Reference

Graphs

Represent relationships and trace traversals, shortest paths, and spanning-tree algorithms.

ReferenceAbout 2 min

This page lists the library modules for Graphs. The lesson is Graph traversals.

This page is the module index for graphs.

  • graphs/adjacency_list.py — adjacency lists. DFS and BFS are O(V + E). The teaching dijkstra_distances scans all unsettled vertices each step, so O(V²) time on dense graphs.

Focused lessons

  • graphs/algorithms.py — BFS distances, topological sort, cycle detection, Kosaraju SCCs, Bellman-Ford, heap Dijkstra, Kruskal, Prim, 0-1 BFS, Floyd-Warshall, bipartite test.

Industry

A working engineer stores a sparse graph as adjacency lists and searches with the structure the weights require. Unweighted breadth-first search uses collections.deque, which Python documents with approximately O(1) appends and pops at either end. Non-negative weights use heapq, the min-heap whose smallest item is the root. The adjacency-list scan is the Dijkstra that heap replaces.

Implementation and tests Optional reference

Library code 2

  • bitsandbytes.graphs.adjacency_list
  • bitsandbytes.graphs.algorithms

Use these references to compare the explanation with repository code and tests. A test link means it imports a lesson symbol; it does not by itself claim complete behavior coverage.