📘 Data Structures - Full Implementation (Week 1)
This project contains the implementation of fundamental data structures in C++ as part of Week 1 practice.
It includes all required structures for Day 1, Day 2, Day 3, Day 4, and Day 5 tasks, each implemented in its own .cpp file and tested using a main() function.
A resizable array that automatically expands when full.
-
Time Complexity:
- Access: O(1)
- Insert (end): Amortized O(1), Worst O(n)
- Delete: O(n)
-
Space Complexity: O(n)
-
Use Case: Used in dynamic containers like
std::vector.
A list of nodes where each node points only to the next node.
- Time Complexity: O(1) insert at head, O(n) for search/delete.
- Space Complexity: O(n)
- Use Case: Useful for linear data where frequent insertions/removals occur at the front.
Implements LIFO using a dynamic array.
- Time Complexity: O(1) for push/pop/peek.
- Space Complexity: O(n)
- Use Case: Expression evaluation, backtracking.
Stack operations using linked nodes instead of array.
- Time Complexity: O(1) for push/pop/peek.
- Space Complexity: O(n)
- Use Case: Better when size is unknown or fluctuating.
FIFO implementation using a circular array.
- Time Complexity: O(1) for enqueue/dequeue/peek.
- Space Complexity: O(n)
- Use Case: Print queues, scheduling tasks.
Queue using dynamic memory allocation with head/tail.
- Time Complexity: O(1) for all operations.
- Space Complexity: O(n)
- Use Case: When queue size changes dynamically.
Each node points to both previous and next node.
- Time Complexity: O(1) insert/delete at head/tail, O(n) search.
- Space Complexity: O(n)
- Use Case: Navigation history (browser/music players).
The last node connects back to the first.
- Time Complexity: O(1) insert at front/tail.
- Space Complexity: O(n)
- Use Case: Round-robin scheduling, loops.
Basic tree with left and right child nodes.
- Supports: Inorder, Preorder, Postorder traversal
- Includes: Height calculation
- Time Complexity:
- Insert/Search: O(n)
- Traversals: O(n)
- Height: O(n)
- Space Complexity: O(n)
- Use Case: Hierarchical data like file systems or expressions.
Sorted binary tree for fast search and insertion.
- Time Complexity:
- Average Case: O(log n)
- Worst Case: O(n)
- Space Complexity: O(n)
- Use Case: Dynamic sets, database indexing.
Priority queue implementation using binary heap.
- Time Complexity:
- Insert: O(log n)
- Get/Remove Min: O(log n)
- Space Complexity: O(n)
- Use Case: Task scheduling, shortest path algorithms.
Implements separate chaining for collision handling.
- Time Complexity:
- Average Case: O(1)
- Worst Case: O(n)
- Space Complexity: O(n)
- Use Case: Fast key-based access.
Undirected graph using adjacency list.
- Time Complexity:
- Add Edge: O(1)
- Traversal: O(V + E)
- Space Complexity: O(V + E)
- Use Case: Networks, dependency resolution.
Two basic traversal methods.
- BFS: Queue-based
- DFS: Stack-based (recursive)
- Time Complexity: O(V + E)
- Space Complexity: O(V)
- Use Case: Search, AI, connectivity check.
Specialized tree for prefix operations.
- Time Complexity:
- Insert/Search: O(L) where L is length of string
- Space Complexity: O(n * L)
- Use Case: Auto-completion, spell-checking.
Tracks and merges disjoint sets.
- Time Complexity: O(α(n)) using path compression and union by rank
- Space Complexity: O(n)
- Use Case: Kruskal’s MST, network grouping.
- Open the project in Visual Studio 2022 (or compatible C++ IDE).
- Go to any
.cppfile insideDay1/toDay5/. - Right-click inside the
main()and select Run Without Debugging. - Output will show the functionality of the selected structure.
| Structure | Use Case |
|---|---|
| Dynamic Array | Flexible storage |
| Singly Linked List | Sequential access |
| Stack (Array/List) | Undo, backtracking |
| Queue (Array/List) | Scheduling, buffering |
| Doubly Linked List | Bidirectional navigation |
| Circular Linked List | Circular processing |
| Binary Tree | Hierarchical data |
| Binary Search Tree | Fast lookup |
| Min Heap | Priority management |
| Hash Table | Key-value storage |
| Graph (Adjacency List) | Network models |
| Graph Traversal | Explore connected paths |
| Trie | Prefix-based string search |
| Union-Find | Group tracking |
- Language: C++
- IDE: Visual Studio 2022
- Structure:
Day1/– Basic Lists and StackDay2/– Queues and Advanced ListsDay3/– TreesDay4/– Hashing, Heap, GraphsDay5/– Graph Traversal, Trie, Union-Find