https://github.com/anshmnsoni/graphs
All about Graph Theory (Discrete Mathematics)
https://github.com/anshmnsoni/graphs
adjacency-matrix collections discrete-mathematics math matrix object-oriented-programming python sympy tabulate
Last synced: 3 months ago
JSON representation
All about Graph Theory (Discrete Mathematics)
- Host: GitHub
- URL: https://github.com/anshmnsoni/graphs
- Owner: AnshMNSoni
- License: bsd-3-clause
- Created: 2024-10-14T14:32:18.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-04T06:35:04.000Z (3 months ago)
- Last Synced: 2025-07-04T07:32:00.850Z (3 months ago)
- Topics: adjacency-matrix, collections, discrete-mathematics, math, matrix, object-oriented-programming, python, sympy, tabulate
- Language: Python
- Homepage:
- Size: 818 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About Graph Theory:
This repository contains a Python implementation of the famous **adjacency matrix** and **Graph Ploting** using the `Graph Theory` (Discrete Mathematics). The implementation includes generating an **adjacency matrix** for any given graph, which is represented by a set of vertices and edges.
## Table of Contents
- [Introduction](#introduction)
- [Graph Representation](#graph-representation)
- [Usage](#usage)
- [Dependencies](#dependencies)
- [Example](#example)
- [Output Format](#output-format)
- [Contact](#contact)## Introduction
An Adjacency Matrix is a square matrix used to represent a graph, where:
- Rows and columns represent vertices (nodes) of the graph.
- Entries (elements) in the matrix indicate edge connections between vertices.## Graph Representation
The graph is represented using Python's `namedtuple` for defining the vertices and edges. Here's how the Konigsberg bridge problem is modeled:
```python
Graph = namedtuple('Graph', ['vertices', 'edges'])vertices = ['A', 'B', 'C', 'D']
edges = [
("A", "B"),
("A", "B"),
("A", "C"),
("A", "C"),
("A", "D"),
("B", "D"),
("C", "D")
]G = Graph(vertices=vertices, edges=edges)
```## Usage
1) Clone the repository:
```python
git clone https://github.com/yourusername/konigsberg-graph.git
```2) Run the Python script to generate the adjacency matrix:
```python
python graph.py
```## Dependencies
Libraries: 1) collections 2) tabulateYou can install libraries via pip if needed:
```python
pip install tabulate
```
```python
pip install collections
```## Example
Here's an example adjacency matrix for the Konigsberg graph:
```
vertices = ['A', 'B', 'C', 'D']
edges = [
("A", "B"),
("A", "B"),
("A", "C"),
("A", "C"),
("A", "D"),
("B", "D"),
("C", "D")
]G = Graph(vertices=vertices, edges=edges)
matrix = adjacency_matrix(G)```
## Output Format
```
╒═══╤═══╤═══╤═══╕
│ 0 │ 2 │ 2 │ 1 │
├───┼───┼───┼───┤
│ 2 │ 0 │ 0 │ 1 │
├───┼───┼───┼───┤
│ 2 │ 0 │ 0 │ 1 │
├───┼───┼───┼───┤
│ 1 │ 1 │ 1 │ 0 │
╘═══╧═══╧═══╧═══╛
```## Preview:
### 📢 Connect with Me
If you found this project helpful or have any suggestions, feel free to connect:- [](https://www.linkedin.com/in/anshmnsoni)
- [](https://github.com/AnshMNSoni)
- [](https://www.reddit.com/user/AnshMNSoni)### Thankyou 💫