Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-11 Thread Gregory Ewing
Steven D'Aprano wrote: Secondly, O(N*log N) applies to *comparison sorts*. Non-comparison sorts such as radix-, counting- and bucket-sort have average case complexity of O(N). They require additional space, though. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Tim Daneliuk
On 02/10/2014 04:20 AM, Sturla Molden wrote: In general, we cannot sort a sequence in O(n) time. O(n log n) is the lower bound on the complexity. Only true for sorting that involve comparison. However, sorts that use the values of the inputs as positional keys have a lower bound complexity (om

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Steven D'Aprano
On Mon, 10 Feb 2014 10:20:33 +, Sturla Molden wrote: > Wesley wrote: >> [Wesley] This is not homework:-) >> And actually I am new to algorithm, so you guys can feel free to say >> anything you want > > In general, we cannot sort a sequence in O(n) time. O(n log n) is the > lower bound on the

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Gregory Ewing
Chris Angelico wrote: mylist = reorder_generator(mylist) You can iterate over it, but can't index it. But hey, it complies with the space/time requirements! Rather than a generator, you could use a view object that rearranges the indices when you access an element. That would comply with the s

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Oscar Benjamin
On 10 February 2014 15:52, Chris Angelico wrote: > On Tue, Feb 11, 2014 at 2:45 AM, Oscar Benjamin > wrote: >> Something like >> >> mylist[:] = reorder_generator(mylist) >> >> won't work because the generator would need to access the data >> non-sequentially (it would need to read elements af

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Chris Angelico
On Tue, Feb 11, 2014 at 2:45 AM, Oscar Benjamin wrote: > Something like > > mylist[:] = reorder_generator(mylist) > > won't work because the generator would need to access the data > non-sequentially (it would need to read elements after they were > overwritten). This would have O(1) space an

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Oscar Benjamin
On 10 February 2014 15:03, Sturla Molden wrote: > Chris Angelico wrote: > >> That's assuming it really is a sort operation. The problem description >> isn't entirely clear on this point, but if it's actually a zip, then >> it can definitely be done in O(n). > > Ah, I didn't read it carefully enou

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Chris Angelico
On Tue, Feb 11, 2014 at 2:03 AM, Sturla Molden wrote: > Chris Angelico wrote: > >> That's assuming it really is a sort operation. The problem description >> isn't entirely clear on this point, but if it's actually a zip, then >> it can definitely be done in O(n). > > Ah, I didn't read it carefull

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Sturla Molden
Chris Angelico wrote: > That's assuming it really is a sort operation. The problem description > isn't entirely clear on this point, but if it's actually a zip, then > it can definitely be done in O(n). Ah, I didn't read it carefully enough. :-) Granted, a zip can be done in O(n) time and O(1)

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Chris Angelico
On Mon, Feb 10, 2014 at 9:20 PM, Sturla Molden wrote: > Wesley wrote: >> [Wesley] This is not homework:-) >> And actually I am new to algorithm, so you guys can feel free to say >> anything you want > > In general, we cannot sort a sequence in O(n) time. O(n log n) is the lower > bound on the co

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Sturla Molden
Wesley wrote: > [Wesley] This is not homework:-) > And actually I am new to algorithm, so you guys can feel free to say anything > you want In general, we cannot sort a sequence in O(n) time. O(n log n) is the lower bound on the complexity. -- https://mail.python.org/mailman/listinfo/python-l

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Dave Angel
Wesley Wrote in message: > >> > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx >> > always exist in pair. So, now, how to change the sequence to >> > a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). >> >> >> >> The two halves of the list are already s

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Wesley
[Wesley] This is not homework:-) And actually I am new to algorithm, so you guys can feel free to say anything you want -- https://mail.python.org/mailman/listinfo/python-list

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Wesley
> > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > > time complexity as O(n) and space as O(1). > > > > The two halves of the list are already sorted, yes? [Wesley] No, not sorted

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Wesley
在 2014年2月9日星期日UTC+8下午11时48分17秒,Oscar Benjamin写道: > Please don't top-post. > > On Feb 9, 2014 2:40 PM, "Ni Wesley" wrote: > > > > > > Yes, with no new list, otherwise, space won't to be O(1) > > Did you read the link I posted: > > >> http://en.wikipedia.org/wiki/In-place_matrix_transposition >

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Roy Smith
In article <52f80bca$0$29972$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Sun, 09 Feb 2014 10:05:02 -0500, Roy Smith wrote: > > > Is this a homework problem? > > and then (paraphrasing): > > > working code that solves the problem > > /headdesk I gave him the benefit of t

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Steven D'Aprano
On Sun, 09 Feb 2014 10:05:02 -0500, Roy Smith wrote: > Is this a homework problem? and then (paraphrasing): > working code that solves the problem /headdesk -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Steven D'Aprano
On Sun, 09 Feb 2014 04:13:50 -0800, Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx > always exist in pair. So, now, how to change the sequence to > a1,b1,...,an,bn, with time complex

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Oscar Benjamin
Please don't top-post. On Feb 9, 2014 2:40 PM, "Ni Wesley" wrote: > > Yes, with no new list, otherwise, space won't to be O(1) Did you read the link I posted: >> http://en.wikipedia.org/wiki/In-place_matrix_transposition Oscar -- https://mail.python.org/mailman/listinfo/python-list

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Roy Smith
In article , Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > time complexity as O(n) and s

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Ni Wesley
Yes, with no new list, otherwise, space won't to be O(1) Wesley 2014年2月9日 下午10:31于 "Oscar Benjamin" 写道: > Please reply to the list rather than directly to me so that other > people can see the answer to my question and offer you help. > > On 9 February 2014 14:04, Ni Wesley wrote: > > 2014年2月9日

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Oscar Benjamin
Please reply to the list rather than directly to me so that other people can see the answer to my question and offer you help. On 9 February 2014 14:04, Ni Wesley wrote: > 2014年2月9日 下午9:41于 "Oscar Benjamin" 写道: > >> On 9 February 2014 12:13, Wesley wrote: >> > Hi guys, >> >Here is one questi

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Oscar Benjamin
On 9 February 2014 12:13, Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > time complexity as O(

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Chris Angelico
On Sun, Feb 9, 2014 at 11:13 PM, Wesley wrote: > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > time complexity as O(n) and space as O(1). The two halves of the list are already sorted,

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Asaf Las
On Sunday, February 9, 2014 2:13:50 PM UTC+2, Wesley wrote: > Hi guys, >Here is one question related to algorithm. > Details here: > > here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always > exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with > t

Sort one sequence by O(n) in time and O(1) in space

2014-02-09 Thread Wesley
Hi guys, Here is one question related to algorithm. Details here: here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with time complexity as O(n) and space as O(1). Any comments will be appreciate