Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65761
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <oscar.j.benjamin@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.078 |
| X-Spam-Evidence | '*H*': 0.84; '*S*': 0.00; 'list?': 0.07; 'okay': 0.09; 'cc:addr:python-list': 0.11; "(it's": 0.16; 'algorithm.': 0.16; 'cc:name:python list': 0.16; 'guys,': 0.16; 'in-place': 0.16; 'pair.': 0.16; 'subject:Sort': 0.16; 'swaps': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'help.': 0.21; 'input': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'subject:) ': 0.29; 'related': 0.29; 'message- id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; 'bunch': 0.31; 'url:wikipedia': 0.31; 'subject:time': 0.33; 'could': 0.34; 'problem': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'subject:one': 0.36; 'done': 0.36; 'doing': 0.36; 'url:org': 0.36; 'so,': 0.37; 'list': 0.37; 'rather': 0.38; 'space': 0.40; 'how': 0.40; 'algorithms': 0.60; 'new': 0.61; "you're": 0.61; 'first': 0.61; 'here:': 0.62; 'offer': 0.62; 'information': 0.63; 'to:addr:gmail.com': 0.65; 'details': 0.65; 'here': 0.66; 'reply': 0.66; 'yes': 0.68; 'paper': 0.75; 'charset:gb2312': 0.80; 'complexity': 0.84; 'oscar': 0.84; 'subject:space': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=bhAd8gcKlcuwUCjVd/gu903mnk60msJUoZJO4d6AXs8=; b=ZNKNM+VgwsvUFfdN3RmsunI1TRz+DvxhxZoblYrwk6oL/LeeEgLR0uNPLsmeNIxO2/ EX/5P2DKaVPHCoeT5hpdK8RGC7ZNCgVy4LdP3YcX1R/g2fCffFfFiXj2c+8gE7kvN9GF Q0qOyrNyD6Tnt2S8iuSb6ItDobexC4ups5iJPl5mD5O5N0Nwhpe26+WfsSpSD+fAlF3b BDrZJXCpBOlCmUbbwXtQ4yzoJeLuCythGU3OoLnfOoxGjHnJdmUT+bH+TKuydQd2OaFD YPZswupe+epY7T0JZNKwlm8VlJPRJn2mwTozoep2/4lrjzMm9zAk0vcKH8vtc0QD7Jzu R+pQ== |
| X-Received | by 10.52.121.113 with SMTP id lj17mr16537488vdb.21.1391956275813; Sun, 09 Feb 2014 06:31:15 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <CAHVvXxSi+wHuC+ssMQkf5mFNaT0rrq-zHoW1UsTHb+XdddrORQ@mail.gmail.com> |
| References | <ae372652-0f1c-4d79-82db-a522eb592579@googlegroups.com> <CAHVvXxSi+wHuC+ssMQkf5mFNaT0rrq-zHoW1UsTHb+XdddrORQ@mail.gmail.com> |
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | Sun, 9 Feb 2014 14:30:55 +0000 |
| Subject | Re: Sort one sequence by O(n) in time and O(1) in space |
| To | Wesley <nispray@gmail.com> |
| Content-Type | text/plain; charset=GB2312 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | Python List <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6589.1391956278.18130.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1391956278 news.xs4all.nl 2836 [2001:888:2000:d::a6]:44114 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:65761 |
Show key headers only | View raw
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 <nispray@gmail.com> wrote: > 2014年2月9日 下午9:41于 "Oscar Benjamin" <oscar.j.benjamin@gmail.com>写道: > >> On 9 February 2014 12:13, Wesley <nispray@gmail.com> 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 space as O(1). >> >> Do you mean that you have a list and you want to rearrange the >> elements in-place without creating a new list? > > Yes Okay so if you're going to do it with O(1) space then it's going to have to be done with a whole bunch of swaps. Have a think with pen and paper about how you could do a sequence of swaps that would rearrange the order to the one that you want (it's actually a harder problem than it looks at first glance). This is an example of what is known as "transposition" and much information is available about algorithms for doing this in-place: http://en.wikipedia.org/wiki/In-place_matrix_transposition Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Sort one sequence by O(n) in time and O(1) in space Wesley <nispray@gmail.com> - 2014-02-09 04:13 -0800
Re: Sort one sequence by O(n) in time and O(1) in space Asaf Las <roegltd@gmail.com> - 2014-02-09 04:29 -0800
Re: Sort one sequence by O(n) in time and O(1) in space Chris Angelico <rosuav@gmail.com> - 2014-02-09 23:39 +1100
Re: Sort one sequence by O(n) in time and O(1) in space Wesley <nispray@gmail.com> - 2014-02-09 18:09 -0800
Re: Sort one sequence by O(n) in time and O(1) in space Dave Angel <davea@davea.name> - 2014-02-09 22:00 -0500
Re: Sort one sequence by O(n) in time and O(1) in space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-09 13:41 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-09 14:30 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Ni Wesley <nispray@gmail.com> - 2014-02-09 22:40 +0800
Re: Sort one sequence by O(n) in time and O(1) in space Roy Smith <roy@panix.com> - 2014-02-09 10:05 -0500
Re: Sort one sequence by O(n) in time and O(1) in space Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-09 23:14 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Roy Smith <roy@panix.com> - 2014-02-09 19:15 -0500
Re: Sort one sequence by O(n) in time and O(1) in space Wesley <nispray@gmail.com> - 2014-02-09 18:26 -0800
Re: Sort one sequence by O(n) in time and O(1) in space Sturla Molden <sturla.molden@gmail.com> - 2014-02-10 10:20 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Steven D'Aprano <steve@pearwood.info> - 2014-02-11 05:20 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-12 11:56 +1300
Re: Sort one sequence by O(n) in time and O(1) in space Tim Daneliuk <tundra@tundraware.com> - 2014-02-10 23:37 -0600
Re: Sort one sequence by O(n) in time and O(1) in space Tim Daneliuk <tundra@tundraware.com> - 2014-02-10 23:37 -0600
Re: Sort one sequence by O(n) in time and O(1) in space Chris Angelico <rosuav@gmail.com> - 2014-02-10 21:37 +1100
Re: Sort one sequence by O(n) in time and O(1) in space Sturla Molden <sturla.molden@gmail.com> - 2014-02-10 15:03 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Chris Angelico <rosuav@gmail.com> - 2014-02-11 02:23 +1100
Re: Sort one sequence by O(n) in time and O(1) in space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-10 15:45 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Chris Angelico <rosuav@gmail.com> - 2014-02-11 02:52 +1100
Re: Sort one sequence by O(n) in time and O(1) in space Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-11 13:19 +1300
Re: Sort one sequence by O(n) in time and O(1) in space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-10 16:41 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-09 15:48 +0000
Re: Sort one sequence by O(n) in time and O(1) in space Wesley <nispray@gmail.com> - 2014-02-09 18:07 -0800
Re: Sort one sequence by O(n) in time and O(1) in space Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-09 21:31 +0000
csiph-web