This repository contains implementations of various data structures and algorithms in C++. The project is organized into different modules, each focusing on specific concepts and implementations.
DataStructure-alg/
βββ π Sortings/
β βββ π Comparsion-based-sorting/
β β βββ π Quadratic-Sorting-Algorithms/
β β β βββ π InsertionSort.h
β β β βββ π BubbleSort.h
β β β βββ π SelectionSort.h
β β βββ π Sub-quadratic-Sorting-Algorithms/
β β βββ π MergeSort.h
β β βββ π QuickSort.h
β β βββ π HeapSort.h
β β βββ π ShellSort.h
β βββ π linear-sorting-algorithms/
β β βββ π CountSort.h
β β βββ π RadixSort.h
β β βββ π BucketSort.h
β βββ π ComplexAlgrothms/
β βββ π rand_select.h
βββ π Liked-Lists/
β βββ π Single-Linked-List.h
β βββ π Array-Based-Lists.h
β βββ π Doubly-Linked-Lists.h
β βββ π Circular-linked-list.h
β βββ π ordered-linked.list.h
βββ π Stacks-and-Queues/
β βββ π Stack/
β β βββ π Stack.h
β βββ π Queues/
β βββ π Queues.h
β βββ π Array-Based-Queue.h
β βββ π circular_array_queue.h
β βββ π DLL_queue.h
β βββ π SLL_queue.h
β βββ π priority_queue.h
βββ π tree/
β βββ π Heap/
β β βββ π Max-priority-queue.h
β β βββ π heap.h
β βββ π BST/
β β βββ π BSTNode.h
β βββ π AVL/
β βββ π AVL.h
βββ π RecursionExamples/
β βββ π Examples.h
βββ π main.cpp
βββ π CMakeLists.txt
The project implements various types of linked lists:
-
Single Linked List [
Single-Linked-List.h]- Operations:
- Insertion (Front/Back/Position): O(1) / O(n)
- Deletion (Front/Back/Position): O(1) / O(n)
- Search: O(n)
- Traversal: O(n)
- Operations:
-
Array-Based List [
Array-Based-Lists.h]- Operations:
- Insertion: O(n)
- Deletion: O(n)
- Access: O(1)
- Search: O(n)
- Operations:
-
Doubly Linked List [
Doubly-Linked-Lists.h]- Operations:
- Insertion (Front/Back/Position): O(1)
- Deletion (Front/Back/Position): O(1)
- Forward/Backward Traversal: O(n)
- Search: O(n)
- Operations:
-
Circular Linked List [
Circular-linked-list.h]- Operations:
- Insertion: O(1) at head/tail, O(n) at position
- Deletion: O(1) at head/tail, O(n) at position
- Search: O(n)
- Rotation: O(1)
- Operations:
-
Ordered Linked List [
ordered-linked.list.h]- Operations:
- Insertion (Maintaining Order): O(n)
- Deletion: O(n)
- Search: O(n)
- IsSorted Check: O(n)
- Operations:
Implementation of various stack and queue data structures:
-
Stack [
Stack.h]- Operations:
- Push: O(1)
- Pop: O(1)
- Top: O(1)
- IsEmpty: O(1)
- Operations:
-
Queue Implementations
-
Basic Queue [
Queues.h]- Enqueue/Dequeue: O(1)
- Front/Rear: O(1)
- Memory Management: Dynamic
-
Array Based Queue [
Array-Based-Queue.h]- Enqueue/Dequeue: O(1) amortized
- Fixed Size Operations
- Memory Management: Static
-
Circular Array Queue [
circular_array_queue.h]- Enqueue/Dequeue: O(1)
- Space Efficient
- Wrap-around Implementation
-
Double Linked List Queue [
DLL_queue.h]- Enqueue/Dequeue: O(1)
- Bidirectional Operations
- Memory Management: Dynamic
-
Single Linked List Queue [
SLL_queue.h]- Enqueue/Dequeue: O(1)
- Memory Efficient
- FIFO Implementation
-
Priority Queue [
priority_queue.h]- Enqueue: O(log n)
- Dequeue: O(log n)
- Peek: O(1)
- Heap-based Implementation
-
Implementation of various tree data structures:
-
Binary Search Tree [
BSTNode.h]- Operations:
- Insertion: O(h)
- Deletion: O(h)
- Search: O(h)
- Traversal: O(n)
- Operations:
-
AVL Tree [
AVL.h]- Operations:
- Insertion: O(log n)
- Deletion: O(log n)
- Search: O(log n)
- Rebalancing: O(1)
- Height: Always O(log n)
- Operations:
-
Heap Implementations
-
Basic Heap [
heap.h]- Insert: O(log n)
- Delete: O(log n)
- Heapify: O(n)
-
Max Priority Queue [
Max-priority-queue.h]- Insert: O(log n)
- Extract Max: O(log n)
- Get Max: O(1)
- Increase Key: O(log n)
-
Comprehensive collection of sorting algorithms:
-
Quadratic Sorting Algorithms
-
Bubble Sort [
BubbleSort.h]- Time: O(nΒ²)
- Space: O(1)
- Stable: Yes
-
Selection Sort [
SelectionSort.h]- Time: O(nΒ²)
- Space: O(1)
- Stable: No
-
Insertion Sort [
InsertionSort.h]- Time: O(nΒ²)
- Space: O(1)
- Best Case: O(n)
-
-
Sub-quadratic Sorting
-
Merge Sort [
MergeSort.h]- Time: O(n log n)
- Space: O(n)
- Stable: Yes
-
Quick Sort [
QuickSort.h]- Time: Average O(n log n), Worst O(nΒ²)
- Space: O(log n)
- In-place: Yes
-
Heap Sort [
HeapSort.h]- Time: O(n log n)
- Space: O(1)
- In-place: Yes
-
Shell Sort [
ShellSort.h]- Time: O(n log n) to O(nΒ²)
- Space: O(1)
- Adaptive: Yes
-
-
Linear-time Sorting
-
Count Sort [
CountSort.h]- Time: O(n + k)
- Space: O(k)
- Stable: Yes
-
Radix Sort [
RadixSort.h]- Time: O(d * (n + k))
- Space: O(n + k)
- Stable: Yes
-
Bucket Sort [
BucketSort.h]- Time: Average O(n + k)
- Space: O(n + k)
- Distribution dependent
-
Advanced algorithm implementations:
- Randomized Select [
rand_select.h]- Average Time: O(n)
- Worst Time: O(nΒ²)
- Selection algorithm for kth smallest element
- Based on QuickSort partitioning
Classic recursion problem implementations:
-
Factorial [
Examples.h]- Time: O(n)
- Space: O(n)
- Recursive implementation
-
Tower of Hanoi [
Examples.h]- Time: O(2βΏ)
- Space: O(n)
- Classic recursion problem
- C++ Compiler (C++20 or later)
- CMake (3.10 or later)
- Windows/Linux/MacOS operating system
- Clone the repository
- Create a build directory:
mkdir build cd build - Generate build files:
cmake ..
- Build the project:
cmake --build .
After building, run the executable:
./final_revisionThe project includes a PowerShell build script (build.ps1) that provides additional build options:
- Clean build:
./build.ps1 -Clean - Debug build:
./build.ps1 -Debug - Release build:
./build.ps1 -Config Release - Custom build directory:
./build.ps1 -BuildDir custom_dir
- All header files (.h) contain both declarations and implementations
- Implementation follows modern C++ practices
- Consistent naming conventions throughout the codebase
- Comprehensive error handling and input validation
- The project uses clang-format for consistent code formatting
- Style configuration is provided in
.clang-formatfile - Follows modern C++ coding guidelines
- Comprehensive comments and documentation
The main program provides several testing features:
- Input validation for all operations
- Boundary condition testing
- Performance measurement options
- Memory leak detection (in debug mode)
- Error handling demonstration
The main program provides a comprehensive menu system to test:
- All sorting algorithms with custom input
- Linked list operations
- Stack and queue operations
- Tree structure operations
- Recursion examples
Each module can be tested independently through the menu interface.
Feel free to contribute to this project by:
- Fork the repository
- Create a new feature branch
- Commit your changes
- Create a pull request
This project is open source and available under the MIT License.
Made with β€οΈ using C++