Data structures from scratch
- Static Array Implementation
- Implement a fixed-size array using Python's primitive
ctypesarray. - Implement
__getitem__(index)and__setitem__(index, value). - Enforce strict index out-of-bounds error handling.
- Implement a fixed-size array using Python's primitive
- Dynamic Array Implementation
- Create a custom dynamic list using
ctypes. - Track
size(elements currently filled) andcapacity(allocated blocks). - Implement automatic geometric expansion (resize to doubling capacity when full).
- Implement automatic geometric contraction (shrink capacity by half when 1/4 full).
- Implement
append(element),insert(index, element), anddelete(index).
- Create a custom dynamic list using
- Singly Linked List
- Create a
Nodeclass with pointersdataandnext. - Implement
insert_at_head(),insert_at_tail(), anddelete_node(value). - Implement
reverse_list()(In-place pointer reversal).
- Create a
- Doubly Linked List
- Modify
Nodeto include pointersprevandnext. - Track both
headandtailnodes within the list instance. - Implement bidirectional traversal methods.
- Modify
- Circular Linked List
- Connect the
tail.nextreference back to theheadnode. - Implement split-list operations and cyclic infinite loop detection.
- Connect the
- Static Array-Based Stack
- Initialize with a strict maximum bound capacity constraint.
- Track top element index location explicitly.
- Implement
push(),pop(),peek(),is_empty(), andis_full().
- Linked-List-Based Stack
- Create a dynamic stack without bound limitations using your
Nodeclass. - Set insertions and deletions to point directly at the
headnode for$O(1)$ operations. - Implement
push(),pop(), andpeek().
- Create a dynamic stack without bound limitations using your
- Circular Array-Based Queue
- Allocate a fixed-size underlying container array.
- Explicitly track tracking indices
frontandrear. - Use modular arithmetic:
rear = (rear + 1) % capacityfor bounds management. - Implement
enqueue(),dequeue(),is_empty(), andis_full().
- Linked-List-Based Queue
- Track distinct
frontpointers andrearpointers inside the tracking instance. - Implement
enqueue()at the tail node anddequeue()at the head node.
- Track distinct
- Circular Array Deque
- Build using a fixed size array base layout with circular pointer wrapping.
- Implement
add_first(),add_last(),remove_first(), andremove_last().
- Doubly Linked List Deque
- Build using structural pointer node modifications on both ends.
- Implement
add_first(),add_last(),remove_first(), andremove_last().
- Hash Table with Chaining (Separate Chaining)
- Implement a custom hash calculation algorithm using string polynomial conversion.
- Resolve array collision paths using your custom Singly Linked List objects.
- Implement
put(key, value),get(key), andremove(key).
- Hash Table with Open Addressing (Linear Probing)
- Resolve internal address conflicts by shifting sequentially down indices:
(hash(k) + i) % capacity. - Support soft deletion using dummy tombstone sentinel objects to prevent query breakages.
- Implement automatic dynamic map resizes when load balancing metrics cross a 0.70 threshold.
- Resolve internal address conflicts by shifting sequentially down indices:
- Binary Search Tree (BST)
- Implement manual pointer leaf nodes containing
left,right, andvalue. - Implement recursive
insert(),search(), and node-shiftingdelete(). - Implement standard tree traversals:
inorder(),preorder(), andpostorder().
- Implement manual pointer leaf nodes containing
- AVL Tree (Self-Balancing Binary Search Tree)
- Track an explicit
heightinteger attribute directly within each tree node. - Calculate structural balance factors:
$\text{height(left)} - \text{height(right)}$ . - Implement balancing adjustments:
left_rotate()andright_rotate().
- Track an explicit
- Binary Heap (Max/Min Priority Queue)
- Implement using a single flattened array index structure.
- Calculate relative positioning coordinates:
$\text{left} = 2i + 1$ ,$\text{right} = 2i + 2$ ,$\text{parent} = \lfloor(i-1)/2\rfloor$ . - Implement structural tree maintenance tools:
sift_up()andsift_down(). - Implement extraction engines:
insert()andextract_root().
📦 python-dsa-scratch ┣ 📂 benchmarks ┃ ┣ 📜 init.py ┃ ┗ 📜 plotter.py # Helper functions to plot time/space complexity ┣ 📂 data_structures ┃ ┣ 📜 init.py ┃ ┣ 📜 arrays.py # Static and Dynamic Arrays ┃ ┣ 📜 linked_lists.py # Singly, Doubly, and Circular ┃ ┣ 📜 stacks.py # Array-based and Linked-List-based ┃ ┣ 📜 queues.py # Linear, Circular, and Linked-List-based ┃ ┣ 📜 deques.py # Array-based and Doubly Linked List ┃ ┣ 📜 hash_tables.py # Chaining and Open Addressing ┃ ┗ 📜 trees.py # BST, AVL, and Binary Heap ┣ 📜 run_benchmarks.py # Main script to execute and save plots ┗ 📜 README.md # Project roadmap