Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual Environment
venv/
env/
ENV/
env.bak/
venv.bak/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Temporary files
*.tmp
*.temp
/tmp/

# Logs
*.log

# Testing
.coverage
.pytest_cache/
.tox/
.coverage.*
coverage.xml
*.cover
.hypothesis/

# Documentation
docs/_build/
208 changes: 206 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,206 @@
# Data-Structure-and-Algorithm-Codes
This repository contains Data Structure and Algorithm codes
# Data Structures and Algorithms Tutorial

A comprehensive collection of data structure and algorithm implementations with detailed explanations, time/space complexity analysis, and practical examples.

## πŸ“š Table of Contents

- [Overview](#overview)
- [Data Structures](#data-structures)
- [Algorithms](#algorithms)
- [Getting Started](#getting-started)
- [Examples](#examples)
- [Contributing](#contributing)

## 🎯 Overview

This repository serves as a complete tutorial and reference for fundamental data structures and algorithms. Each implementation includes:

- **Detailed documentation** with complexity analysis
- **Working code examples** in Python
- **Practical applications** and use cases
- **Step-by-step explanations** of operations

## πŸ“Š Data Structures

### Linear Data Structures

#### Arrays
- **File**: [`data_structures/arrays/array_operations.py`](data_structures/arrays/array_operations.py)
- **Operations**: Insert, Delete, Search, Access
- **Time Complexity**: Access O(1), Search O(n), Insert/Delete O(n)
- **Use Cases**: When you need fast random access by index

#### Linked Lists
- **File**: [`data_structures/linked_lists/singly_linked_list.py`](data_structures/linked_lists/singly_linked_list.py)
- **Operations**: Insert at head/tail/position, Delete, Search
- **Time Complexity**: Access O(n), Insert/Delete O(1) at head
- **Use Cases**: Dynamic size, frequent insertions/deletions at beginning

#### Stacks
- **File**: [`data_structures/stacks/stack.py`](data_structures/stacks/stack.py)
- **Operations**: Push, Pop, Peek, Search
- **Time Complexity**: All operations O(1) except search O(n)
- **Use Cases**: Function calls, expression evaluation, undo operations
- **Example Application**: Balanced parentheses checker included

#### Queues
- **File**: [`data_structures/queues/queue.py`](data_structures/queues/queue.py)
- **Types**: Regular Queue, Circular Queue
- **Operations**: Enqueue, Dequeue, Front, Rear
- **Time Complexity**: All operations O(1)
- **Use Cases**: BFS, process scheduling, handling requests

### Non-Linear Data Structures

#### Binary Search Trees
- **File**: [`data_structures/trees/binary_search_tree.py`](data_structures/trees/binary_search_tree.py)
- **Operations**: Insert, Delete, Search, Traversals
- **Time Complexity**: Average O(log n), Worst O(n)
- **Traversals**: Inorder, Preorder, Postorder, Level-order
- **Use Cases**: Sorted data, range queries, hierarchical data

## πŸš€ Algorithms

### Sorting Algorithms

**File**: [`algorithms/sorting/sorting_algorithms.py`](algorithms/sorting/sorting_algorithms.py)

| Algorithm | Time Complexity | Space | Stable | Description |
|-----------|----------------|-------|---------|-------------|
| **Bubble Sort** | O(nΒ²) | O(1) | Yes | Simple comparison-based sort |
| **Selection Sort** | O(nΒ²) | O(1) | No | Finds minimum and places at beginning |
| **Insertion Sort** | O(nΒ²) | O(1) | Yes | Builds sorted array incrementally |
| **Merge Sort** | O(n log n) | O(n) | Yes | Divide and conquer approach |
| **Quick Sort** | O(n log n) avg | O(log n) | No | Pivot-based partitioning |
| **Heap Sort** | O(n log n) | O(1) | No | Uses binary heap structure |

### Searching Algorithms

**File**: [`algorithms/searching/searching_algorithms.py`](algorithms/searching/searching_algorithms.py)

| Algorithm | Time Complexity | Space | Requirements | Description |
|-----------|----------------|-------|--------------|-------------|
| **Linear Search** | O(n) | O(1) | None | Sequential search |
| **Binary Search** | O(log n) | O(1) | Sorted array | Divide and conquer |
| **Jump Search** | O(√n) | O(1) | Sorted array | Block-based search |
| **Interpolation Search** | O(log log n) | O(1) | Uniformly distributed | Improved binary search |
| **Exponential Search** | O(log n) | O(1) | Sorted array | Find range then binary search |
| **Ternary Search** | O(log₃ n) | O(1) | Sorted array | Divide into three parts |
| **Fibonacci Search** | O(log n) | O(1) | Sorted array | Uses Fibonacci numbers |

## πŸƒβ€β™‚οΈ Getting Started

### Prerequisites
- Python 3.6 or higher

### Running the Code

1. **Clone the repository**:
```bash
git clone https://github.com/0FFSTYLE/Data-Structure-and-Algorithm-Codes.git
cd Data-Structure-and-Algorithm-Codes
```

2. **Run individual data structures**:
```bash
python data_structures/arrays/array_operations.py
python data_structures/linked_lists/singly_linked_list.py
python data_structures/stacks/stack.py
python data_structures/queues/queue.py
python data_structures/trees/binary_search_tree.py
```

3. **Run sorting algorithms**:
```bash
python algorithms/sorting/sorting_algorithms.py
```

4. **Run searching algorithms**:
```bash
python algorithms/searching/searching_algorithms.py
```

5. **Run comprehensive examples**:
```bash
python examples/example_usage.py
```

## πŸ’‘ Examples

The [`examples/example_usage.py`](examples/example_usage.py) file demonstrates:

- **Practical usage** of all data structures
- **Problem-solving** with real-world examples
- **Performance comparisons** between algorithms
- **Best practices** for choosing appropriate data structures

Example output includes:
- Data structure operations and results
- Balanced parentheses validation
- Duplicate finding algorithms
- Sorting and searching performance metrics

## πŸ“ˆ Complexity Quick Reference

### Data Structures Operations

| Data Structure | Access | Search | Insertion | Deletion | Space |
|---------------|--------|---------|-----------|-----------|-------|
| **Array** | O(1) | O(n) | O(n) | O(n) | O(n) |
| **Linked List** | O(n) | O(n) | O(1)* | O(1)* | O(n) |
| **Stack** | O(n) | O(n) | O(1) | O(1) | O(n) |
| **Queue** | O(n) | O(n) | O(1) | O(1) | O(n) |
| **BST** | O(log n) | O(log n) | O(log n) | O(log n) | O(n) |

*\*At head position*

### Algorithm Performance

| Problem | Best Algorithm | Time Complexity | When to Use |
|---------|---------------|----------------|-------------|
| **Sorting small arrays** | Insertion Sort | O(nΒ²) | n < 50 |
| **Sorting large arrays** | Quick/Merge Sort | O(n log n) | General purpose |
| **Searching unsorted** | Linear Search | O(n) | No other option |
| **Searching sorted** | Binary Search | O(log n) | Always prefer this |
| **Finding duplicates** | Hash Set | O(n) | When extra space available |

## πŸ”§ Key Features

- **Educational Focus**: Each implementation prioritizes clarity and understanding
- **Comprehensive Coverage**: From basic arrays to complex tree structures
- **Practical Examples**: Real-world applications and problem-solving
- **Performance Analysis**: Detailed time and space complexity discussions
- **Production Ready**: Clean, well-documented, and tested code

## πŸŽ“ Learning Path

1. **Start with Linear Structures**: Arrays β†’ Linked Lists β†’ Stacks β†’ Queues
2. **Move to Non-Linear**: Binary Search Trees β†’ Hash Tables
3. **Learn Basic Algorithms**: Linear Search β†’ Binary Search β†’ Simple Sorting
4. **Advanced Algorithms**: Efficient Sorting β†’ Advanced Searching
5. **Practice**: Use the examples and create your own implementations

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Areas for contribution:
- Additional data structures (Hash Tables, Heaps, Graphs)
- More algorithms (Dynamic Programming, Graph algorithms)
- Language implementations (Java, C++, JavaScript)
- Performance optimizations
- Additional examples and use cases

## πŸ“ License

This project is open source and available under the [MIT License](LICENSE).

## 🌟 Acknowledgments

- Built for educational purposes
- Suitable for computer science students, coding interviews, and professional development
- Contributions and feedback welcome from the community

---

**Happy Learning! πŸš€**

*Remember: Understanding the concept is more important than memorizing the code. Focus on when and why to use each data structure and algorithm.*
Loading