https://github.com/nelsonbn/algorithms-data-structures-graphs-representation
Algorithms and Data Structures - Graphs Representation
https://github.com/nelsonbn/algorithms-data-structures-graphs-representation
algorithms algorithms-and-data-structures data-structures graphs
Last synced: 9 months ago
JSON representation
Algorithms and Data Structures - Graphs Representation
- Host: GitHub
- URL: https://github.com/nelsonbn/algorithms-data-structures-graphs-representation
- Owner: NelsonBN
- License: mit
- Created: 2025-03-02T12:36:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-03T02:18:29.000Z (about 1 year ago)
- Last Synced: 2025-06-04T21:56:18.872Z (10 months ago)
- Topics: algorithms, algorithms-and-data-structures, data-structures, graphs
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Algorithms and Data Structures - Graphs Representation
## Adjacency Matrix
### Asymptotic Complexity
- Time complexity:
- Insertion: O(1)
- Deletion: O(1)
- Space complexity: O(V^2)
### Pros
- Simple to implement
- Fast to access edge (u, v), O(1), fast to add and remove edges
### Cons
- Space complexity is O(V^2)
- Its not efficient for sparse graphs
### Demos
- [Adjacency Matrix](./src/1.1-adjacency-matrix.py)
- [Undirected Graph](./src/1.2-undirected-graph-matrix.py)
- [Directed Graph](./src/1.3-directed-graph-matrix.py)
- [Adjacency Matrix - Playground](./src/1.4-adjacency-matrix-playground.py)
- [Adjacency Matrix - Weighted](./src/1.5-adjacency-matrix-weighted.py)
## Adjacency List
### Asymptotic Complexity
- Time complexity:
- Insertion: O(V) using list, O(1) using Hash Table
- Deletion: O(V) using list, O(1) using Hash Table
- Space complexity: O(V + E)
### Pros
- Space complexity is O(V + E)
- Efficient for sparse graphs
### Cons
- Slow to access edge (u, v), O(V) using list, but can be O(1) using Hash Table
### Demos
- [Adjacency List](./src/2.1-adjacency-list.py)
- [Adjacency List - With Hash Table](./src/2.2-adjacency-list-with-hashtable.py)
- [Adjacency List - Playground](./src/2.3-adjacency-list-playground.py)
## Edge List
### Asymptotic Complexity
- Time complexity:
- Insertion: O(1)
- Deletion: O(E)
- Space complexity: O(E)
### Pros
- Space complexity is O(E)
- Fast to add edges
### Cons
- Slow to access edge (u, v), O(E)
### Demos
- [Edge List](./src/3.1-edge-list.py)
## References
- [Other Algorithms & Data Structures](https://github.com/NelsonBN/algorithms-data-structures)