Heap implementation in Swift

Hello everyone,

As you can see, I haven’t been blogging for more than three years. That is a long time. But  I had my reasons. A lot has happened in both my personal, and professional life that kept me too busy and sparing little time to focus on blogging. However, I think it is time to start writing again. I like to write about technical topics. So I restart my blogging by kicking it off with this small post, and small snippet of code.

I love the heap data structure. It is a nifty little DS that maintains items in an order, giving you O(1) access to the min/max item, and pops/inserts new items in O(lgN) time. The same structure is used to implement a priority queue, which has uses in many places, e.g. Dijkstra algorithm. So keeping with my habit of implementing a known data structure in short period of free time, I give you a quick implementation of heap written in Swift. Let me know what you think of it, or if you find any problems in it.

Thank you for checking out my blog. I would love to hear from you in the comments section. And lets hope I come up with good content for you to read in the future.

Be Sociable, Share!

Leave a Reply