Re: Mergesort algorithm for linked lists
- From: "user923005" <dcorbit@xxxxxxxxx>
- Date: 29 Jan 2007 16:47:16 -0800
On Jan 29, 3:24 pm, "Stephen Howe" <sjhoweATdialDOTpipexDOTcom> wrote:
He's talking about *natural* mergesort. Natural mergesorting
a sorted linked list of n elements takes n-1 comparisons.
I am unfamiliar with "*natural* mergesort".Natural mergesort is where you take advantage of any builtin order of thelist.
Effectively you split the list into a series of runs as presented in the
initial data.
So if it is already sorted, then the "*natural* mergesort" will generate 1
run of N elements, therefore it is O(N)
But if it in reverse-order, any comparison is such that each element will be
in its own run of length 1.
It is still O(N * log N) to sort as you merge adjacent runs - but you will
do the maximum amount of merging.
Of course, it is a trivial modification to search for partitions that
are either ascending or descending, and tag them as such.
With this simple variant, the reverse ordered set is also fully sorted
after n operations (we just peel the data from the far end instead of
the near end when accessing a reversed partition).
.
- Follow-Ups:
- Re: Mergesort algorithm for linked lists
- From: Stephen Howe
- Re: Mergesort algorithm for linked lists
- References:
- Re: Mergesort algorithm for linked lists
- From: pete
- Re: Mergesort algorithm for linked lists
- From: Googmeister
- Re: Mergesort algorithm for linked lists
- From: pete
- Re: Mergesort algorithm for linked lists
- From: Stephen Howe
- Re: Mergesort algorithm for linked lists
- Prev by Date: Re: Mergesort algorithm for linked lists
- Next by Date: Re: Algorithm to find break in contiguity
- Previous by thread: Re: Mergesort algorithm for linked lists
- Next by thread: Re: Mergesort algorithm for linked lists
- Index(es):