Re: In-place list manipulation
- From: cri@xxxxxxxx (Richard Harter)
- Date: Thu, 22 Nov 2007 17:31:21 GMT
On Thu, 22 Nov 2007 15:30:51 +0200, "Aki Tuomi"
<cmouse@xxxxxxxxxxx> wrote:
When doing mergesort in place, I have ran into a following problem:
How to perform in-place interleave during merge without need of auxilliary
list or array?
I have two sets of indexes: a.start, a.stop and b.start and b.stop. These
contain start and stop indexes in the list where the data is. My question
is, how do I do merge the two into the list in-place?
Example:
List = {1,3,2,5,4,6,7,8,9}
a.start = 1
a.stop = 2
b.start = 3
b.stop = 4
a = {3,2}
b = {5,4}
merge(a,b,List)
List = {1,2,3,4,5,6,7,8,9}
I have solved this now by copying the two segments into temporary arrays and
then copy data back from there, but it does not really feel right. Any
ideas?
Aki Tuomi
It can be done but the process is not simple. I mean it really
is not simple. The known O(n) algorithms are relatively
expensive and take a fair bit of understanding.
Without those, in place merging requires extra space regardless
of whether the subarrays are interleaved or are occupying
contiguous halves.
Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die
.
- References:
- In-place list manipulation
- From: Aki Tuomi
- In-place list manipulation
- Prev by Date: Question on binary search Trie
- Next by Date: Re: mathematical combination
- Previous by thread: In-place list manipulation
- Next by thread: Re: In-place list manipulation
- Index(es):
Relevant Pages
|