Week 6

 

Week 6 Learning Journal: Heaps and Hashing

This week’s module focused on advanced data structures, specifically Heaps and Hash Tables, which are essential for optimizing search and priority-based operations.

Heaps and Priority Queues

I learned about the Max Heap property, where every parent node must be greater than or equal to its children. This structure is particularly efficient for implementing Priority Queues. One of the most interesting takeaways was the $O(n)$ bottom-up heap construction algorithm. Unlike inserting elements one by one ($O(n \log n)$), the bottom-up approach starts from the last non-leaf node and "heapifies" down, which is mathematically more efficient.

I also practiced the mechanics of insert and deleteMax. When deleting the root, we replace it with the last element and percolate it down to maintain the heap property. This ensures that the highest priority element is always accessible at the root in $O(1)$ time.

Hashing and Collision Resolution

The second half of the module introduced Hashing. I explored how a hash function maps a large range of keys into a smaller range of indices. The challenge arises when two keys map to the same index (a collision). We focused on Linear Probing, a form of open addressing where we search for the next available slot sequentially.

A critical concept I mastered was the Load Factor. To maintain efficiency, the table must be resized (rehashing) when the load factor exceeds 0.5. Rehashing requires doubling the size and finding the next prime number to ensure a good distribution of keys, then re-inserting all existing elements into the new table.

These concepts reinforced the importance of choosing the right data structure based on the specific time complexity requirements of an algorithm.

Comments

Popular posts from this blog

Week 4

Week 2

Week 1