Avrêbarra~
LN4: Heap II
- Written on December 22, 2023

heaps

Hola! We meet again in my learning notes.

Today I’m continuing my previous post about Heaps.

You can see the first part here.

Why Heaps? Why Not Just Use Sorted Array?

So from previous post we knew that Heapsthrives when we are looking for max/min values in a series.

It popped me a question also: Just looking for max/min? Why we use Heap? What are the advantages? Isn’t it easier to use just sorted array to seek max/min values?

Apparently, using a sorted array to find the maximum or minimum value is a viable approach. However, heaps offer certain advantages:

While a sorted array can efficiently find the maximum or minimum value, heaps shine in scenarios where dynamic operations and efficient insertion/deletion are key considerations. Their structure allows for quick access to the extremal elements without the need for maintaining a fully sorted order.

For a visual explanation, consider watching this tutorial: Heap vs Others. The visual representation helps illustrate the efficiency of heaps over other possible datastructures.

What are real usecases of for Heaps? Why do I often hear it when talking about memories?

In computer systems, heaps play some roles particularly when managing dynamic memory allocation. The heap data structure is widely employed in various scenarios, including:

Heaps are often associated with memory discussions because they play a key role in dynamic memory allocation and deallocation, contributing to the efficient management of system resources.

Are there any other Heap type other than Max & Min?

Certainly, besides Max and Min Heaps, there are other specialized heap types, each designed for specific use cases and requirements.

These various heap types cater to different requirements and algorithmic complexities, providing flexibility in choosing the most suitable heap for a given application.

Any Other Things I Found Interesting?

Yes, there are some things I also found pretty interesting are:

Heaps as Arrays: It’s very interesting how we can actually represent binary heaps using just a simple array. Tbh when data structures are mentioned I always thought that it would be some variables wrapped class with interactive private functions and such. But turned out a simple binary heap can do with a simple array. Neat.

The Marvelous Heap Sort: a sort that’s utilizing heap, is actually one of the best options available (along with quick and merge sort). What’s interesting is that I didn’t actually understand how Heap Sorts actually work since long time ago when I was learning about Sortings. But when I learnt about Heap, whoa, it made sense. Using heap is a smart choice.

Closing Words

In summary, again, Heaps are cool. Haha. But really, Heaps are undeniably fascinating! Delving into the intricacies of this data structure has been an enlightening journey, revealing a multitude of insights.

May the newfound understanding serve as a valuable asset in our repertoire of problem-solving tools.

Until next time, happy coding!