Why is merge sort worst case run time O (n log n)?

On a “traditional” merge sort, each pass through the data doubles the size of the sorted subsections. After the first pass, the file will be sorted into sections of length two. After the second pass, length four. Then eight, sixteen, etc. up to the size of the file.

It’s necessary to keep doubling the size of the sorted sections until there’s one section comprising the whole file. It will take lg(N) doublings of the section size to reach the file size, and each pass of the data will take time proportional to the number of records.

Leave a Comment