Classic data structures and algorithms implemented from scratch in Python.
Every file is standalone and runnable withpython filename.py.
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | ✅ |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | ✅ |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | ❌ |
| Structure | Access | Search | Insert | Delete |
|---|---|---|---|---|
| Linked List | O(n) | O(n) | O(1) head | O(n) |
| Stack | O(n) | O(n) | O(1) | O(1) |
| Queue | O(n) | O(n) | O(1) | O(1) |
| BST | O(log n)* | O(log n)* | O(log n)* | O(log n)* |
| Hash Table | — | O(1) avg | O(1) avg | O(1) avg |
*BST worst case is O(n) for skewed trees
| Algorithm | Time | Space |
|---|---|---|
| Linear Search | O(n) | O(1) |
| Binary Search | O(log n) | O(1) |
| BFS | O(V + E) | O(V) |
| DFS | O(V + E) | O(V) |
| Dijkstra | O((V+E) log V) | O(V) |
dsa-algorithms-python/
├── sorting/
│ ├── bubble_sort.py # O(n²) comparison sort
│ ├── merge_sort.py # O(n log n) divide and conquer
│ ├── quick_sort.py # O(n log n) partition-based
│ └── comparison.py # Time all 3 algorithms
├── data_structures/
│ ├── linked_list.py # Singly + Doubly linked list
│ ├── stack_queue.py # LIFO stack + FIFO queue
│ ├── binary_search_tree.py # BST with traversals
│ └── hash_table.py # Hash table with chaining
├── searching/
│ ├── linear_search.py # Sequential search
│ └── binary_search.py # Iterative + recursive
├── graphs/
│ ├── graph.py # Adjacency list representation
│ ├── bfs_dfs.py # BFS and DFS traversal
│ └── dijkstra.py # Shortest path with reconstruction
└── README.md
git clone https://github.com/imranalimemon/dsa-algorithms-python.git
cd dsa-algorithms-python
# Run any file directly
python sorting/bubble_sort.py
python data_structures/binary_search_tree.py
python graphs/dijkstra.py
# Run sorting comparison benchmark
python sorting/comparison.py- Trade-offs matter: Bubble Sort is simple but O(n²); Quick Sort is fast but unstable
- Divide and conquer is powerful: Merge Sort, Quick Sort, Binary Search all use it
- Hash tables are O(1) for most operations — but collision handling is critical
- Graph algorithms have broad applications: maps, networks, scheduling
- Space vs time: Merge Sort uses O(n) extra space for guaranteed O(n log n)
MIT License
Built by Imran Ali — MUET Jamshoro, CS 2026