Posted by: **atri** | October 26, 2010

## Sorting in O(n log n) time

In today’s lecture, I mentioned that sorting numbers can be done in time. There are multiple algorithms that can do this and we will see one, called *merge sort* later on in the course.

Below, I’ll describe the *heap sort* algorithm. All the ingredients are already there in Section 2.5 of the book. Below I’ll use notation from Pg. 64 in the text.

I’ll assume that the numbers are given as input in the array and that the algorithm will output the sorted numbers in array .

- .
- For
- For
- .

The fact that this algorithm runs in time follows from the run time complexities of the three procedures used above as mentioned on Pg. 64 of the book. The correctness of the algorithm also follows from the description of the procedures in the book.

As usual, if you have any questions, please use the comments section.

### Like this:

Like Loading...

*Related*

[…] we stated that you can sort the intervals in O(n log n) time (blog post regarding this found here) such that f(i) <= f(i+1) and that we can build the array s[1..n] in O(n) time such that s[i] is […]

By:

Lecture 23 | Companion blog to the CSE 331 blogon October 26, 2010at 8:15 pm