https://github.com/jconleyscales/graph-adjacency-matrix
Undirected weighted graph utilities + Graph class (adjacency matrix) in Python.
https://github.com/jconleyscales/graph-adjacency-matrix
adjacency-matrix data-structures graphs python
Last synced: 3 months ago
JSON representation
Undirected weighted graph utilities + Graph class (adjacency matrix) in Python.
- Host: GitHub
- URL: https://github.com/jconleyscales/graph-adjacency-matrix
- Owner: jconleyscales
- Created: 2025-12-22T04:16:54.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-12-22T04:28:03.000Z (3 months ago)
- Last Synced: 2025-12-23T15:48:31.248Z (3 months ago)
- Topics: adjacency-matrix, data-structures, graphs, python
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Graph (Adjacency Matrix) — Python
Utilities and a `Graph` class for working with an undirected, weighted graph stored as an adjacency matrix.
## Features
- Helper functions to compute vertex/edge counts and shortest/longest edge weights
- `find_popular()` to find the vertex with the most neighbors
- `Graph` class with safe edge operations: `add_edge`, `adjust_edge`, `remove_edge`, `exists_edge`
- Validation: bounds checking, no self-loops, non-negative weights
## How to Run
1. Make sure you have Python 3 installed.
2. Run the file:
```bash```
python graph.py
## Example Usage
```python
from graph import Graph
g = Graph(5)
g.add_edge(0, 1, 7)
g.add_edge(0, 2, 3)
print(g.exists_edge(0, 1)) # True
g.remove_edge(0, 1)
print(g.exists_edge(0, 1)) # False