Skip to content

imranalimemon/dsa-algorithms-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Data Structures & Algorithms in Python

Python DSA License

Classic data structures and algorithms implemented from scratch in Python.
Every file is standalone and runnable with python filename.py.


📊 Time Complexity Table

Sorting Algorithms

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)

Data Structures

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

Search & Graph

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)

📁 Project Structure

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

🚀 How to Run

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

💡 Key Learnings

  1. Trade-offs matter: Bubble Sort is simple but O(n²); Quick Sort is fast but unstable
  2. Divide and conquer is powerful: Merge Sort, Quick Sort, Binary Search all use it
  3. Hash tables are O(1) for most operations — but collision handling is critical
  4. Graph algorithms have broad applications: maps, networks, scheduling
  5. Space vs time: Merge Sort uses O(n) extra space for guaranteed O(n log n)

📄 License

MIT License

Built by Imran Ali — MUET Jamshoro, CS 2026

About

Data structures and algorithms implemented from scratch in Python - sorting, searching, BST, graphs, Dijkstra

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages