My Octopress Blog

A blogging framework for hackers.

Heapsort

I was reading about Algorithm Geeks, a Google Group dedicated to algorithm-related questions apparently. I looked at one of the topics, Unique Elements in an Array, wondering what the chatter looked like.

To remove duplicate elements of an array, the best way I know is to sort your array, and then do a linear traversal, comparing each to its successor, and when they match, deleting the one of them. Quicksort is generally the algorithm-of-choice in large part because of its simplicity, but someone on this thread suggested heapsort - an algorithm of which I had never heard. I looked it over, and was drawn to the article on heaps. On that page, I was looking at an analysis of the time complexity for building the heap, and I got curious about the summation they present (h/2^h). So, I took some time and proved its convergence:

Convergence of Infinite Sum