An open API service indexing awesome lists of open source software.

https://github.com/saadsalmanakram/ds-bigo-complexity

It's all about Data Structures... This repository is designed to provide a comprehensive guide to understanding, implementing, and mastering data structures from the ground up.
https://github.com/saadsalmanakram/ds-bigo-complexity

bigonotation data-structures datastructures datastructures-algorithms timecomplexity

Last synced: 6 months ago
JSON representation

It's all about Data Structures... This repository is designed to provide a comprehensive guide to understanding, implementing, and mastering data structures from the ground up.

Awesome Lists containing this project

README

          

---

# πŸ“š DS-BigO-Complexity

![Algorithms and Complexity](https://cdn.pixabay.com/photo/2023/02/08/08/50/frequency-wave-7776034_1280.jpg)

## πŸ“ Introduction

**DS-BigO-Complexity** is a comprehensive guide to understanding **Data Structures, Algorithms, and Time Complexity**. This repository is designed for beginners and intermediate learners who want to strengthen their problem-solving skills and optimize their code for efficiency.

πŸ”Ή Learn about common **data structures** like arrays, linked lists, trees, graphs, and heaps.
πŸ”Ή Implement and analyze **sorting and searching algorithms**.
πŸ”Ή Master **Big-O Notation** and understand **time & space complexity**.
πŸ”Ή Solve real-world **coding problems** with optimized solutions.

---

## πŸš€ Features

- **In-depth explanations** of fundamental data structures
- **Hands-on implementations** in Python
- **Big-O Complexity Analysis** for each algorithm
- **Visual representations** of sorting & searching algorithms
- **Interview-style problems** with optimal solutions
- **Practice problems & challenges**

---

## πŸ“Œ Prerequisites

Before getting started, ensure you have:

- **Python 3.x** installed β†’ [Download Here](https://www.python.org/downloads/)
- Basic knowledge of programming concepts

---

## πŸ“‚ Repository Structure

```
DS-BigO-Complexity/
│── data_structures/ # Implementations of stacks, queues, linked lists, trees, etc.
│── algorithms/ # Sorting, searching, dynamic programming, graph algorithms
│── complexity_analysis/ # Big-O notation, best-case, worst-case, average-case analysis
│── interview_questions/ # Common DSA questions from tech interviews
│── visualizations/ # Graphical representations of sorting & searching algorithms
│── README.md # Project documentation
└── requirements.txt # Python dependencies
```

---

## ⏳ Understanding Big-O Notation

Big-O notation is used to classify algorithms according to their **runtime complexity**. Here’s a quick reference:

| Complexity | Name | Example |
|------------|-----------------|--------------------------------|
| O(1) | Constant Time | Accessing an array index |
| O(log n) | Logarithmic Time | Binary search |
| O(n) | Linear Time | Iterating through an array |
| O(n log n) | Linearithmic Time | Merge Sort, Quick Sort |
| O(nΒ²) | Quadratic Time | Nested loops (e.g., Bubble Sort) |
| O(2ⁿ) | Exponential Time | Fibonacci recursion |
| O(n!) | Factorial Time | Traveling Salesman Problem |

---

## πŸ› οΈ Example: Implementing a Sorting Algorithm

Here’s an implementation of **Merge Sort**, an O(n log n) sorting algorithm:

```python
def merge_sort(arr):
if len(arr) <= 1:
return arr

mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])

return merge(left_half, right_half)

def merge(left, right):
sorted_arr = []
i = j = 0

while i < len(left) and j < len(right):
if left[i] < right[j]:
sorted_arr.append(left[i])
i += 1
else:
sorted_arr.append(right[j])
j += 1

sorted_arr.extend(left[i:])
sorted_arr.extend(right[j:])

return sorted_arr

# Example Usage
arr = [5, 3, 8, 6, 2, 7, 4, 1]
print("Sorted Array:", merge_sort(arr))
```

Output:
```
Sorted Array: [1, 2, 3, 4, 5, 6, 7, 8]
```

---

## πŸ” Topics Covered

### πŸ“Œ **Data Structures**
- **Arrays & Strings**
- **Linked Lists** (Singly, Doubly, Circular)
- **Stacks & Queues**
- **Hash Tables & Hash Functions**
- **Trees & Binary Search Trees (BSTs)**
- **Heaps & Priority Queues**
- **Graphs (Adjacency List & Matrix)**

### πŸ”’ **Algorithms**
- **Sorting Algorithms:** Bubble, Selection, Insertion, Merge, Quick, Heap Sort
- **Searching Algorithms:** Linear Search, Binary Search
- **Graph Algorithms:** BFS, DFS, Dijkstra’s Algorithm
- **Dynamic Programming:** Fibonacci, Knapsack Problem
- **Divide & Conquer:** Merge Sort, Quick Sort
- **Greedy Algorithms:** Huffman Coding, Activity Selection
- **Backtracking:** N-Queens, Sudoku Solver

---

## πŸ† Problem-Solving Challenges

πŸ“Œ The repository includes **real-world problems** with optimal solutions. Examples:

1️⃣ Find the **two numbers** in an array that sum up to a target (`O(n)`)
2️⃣ Detect a **cycle** in a linked list (`O(n)`)
3️⃣ Find the **lowest common ancestor (LCA)** in a BST (`O(log n)`)
4️⃣ Implement a **LRU Cache** using a HashMap & Doubly Linked List (`O(1)`)
5️⃣ Solve the **N-Queens problem** using Backtracking (`O(N!)`)

---

## πŸ”₯ Sorting Algorithm Visualizations

The repository includes **sorting visualizations** for algorithms like:

| Algorithm | Time Complexity | Visualization |
|-----------|----------------|---------------|
| Bubble Sort | O(nΒ²) | ![Bubble Sort](https://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif) |
| Merge Sort | O(n log n) | ![Merge Sort](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Merge_sort_algorithm_diagram.svg/600px-Merge_sort_algorithm_diagram.svg.png) |
| Quick Sort | O(n log n) | ![Quick Sort](https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif) |

---

## ⚑ How to Run the Code

### 1️⃣ Clone the Repository
```bash
git clone https://github.com/saadsalmanakram/DS-BigO-Complexity.git
cd DS-BigO-Complexity
```

### 2️⃣ Install Dependencies
```bash
pip install -r requirements.txt
```

### 3️⃣ Run Example Scripts
```bash
python algorithms/merge_sort.py
python data_structures/linked_list.py
```

---

## πŸ† Contributing

Contributions are welcome! πŸš€

πŸ”Ή **Fork** the repository
πŸ”Ή Create a new branch (`git checkout -b feature-name`)
πŸ”Ή Commit changes (`git commit -m "Added new sorting algorithm"`)
πŸ”Ή Push to your branch (`git push origin feature-name`)
πŸ”Ή Open a pull request

---

## πŸ“œ License

This project is licensed under the **MIT License** – feel free to use, modify, and share the code.

---

## πŸ”— Resources & References

- [Big-O Complexity Cheat Sheet](https://www.bigocheatsheet.com/)
- [MIT Algorithms Course](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/)
- [CLRS: Introduction to Algorithms](https://en.wikipedia.org/wiki/Introduction_to_Algorithms)

---

## πŸ“¬ Contact

For queries or collaboration, reach out via:

πŸ“§ **Email:** saadsalmanakram1@gmail.com
🌐 **GitHub:** [SaadSalmanAkram](https://github.com/saadsalmanakram)
πŸ’Ό **LinkedIn:** [Saad Salman Akram](https://www.linkedin.com/in/saadsalmanakram/)

---

⚑ **Master Data Structures & Algorithms with Confidence!** ⚑

---