Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91002

Re: Slices time complexity

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'cpython': 0.05; '21,': 0.07; 'linear': 0.07; 'items)': 0.09; 'slices': 0.09; 'cc:addr :python-list': 0.10; 'python': 0.11; 'algorithm': 0.13; 'thu,': 0.15; 'cutoff': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'low.': 0.16; 'quadratic': 0.16; 'sorting': 0.16; 'sure.': 0.16; 'uses,': 0.16; 'worst': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'suggested': 0.20; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'not,': 0.27; 'ago': 0.27; 'message- id:@mail.gmail.com': 0.28; 'asked': 0.28; 'looks': 0.29; 'arithmetic': 0.29; 'comparison': 0.29; 'equally': 0.29; 'fast.': 0.29; 'url:wikipedia': 0.29; 'that.': 0.30; 'url:wiki': 0.30; 'checks': 0.31; 'subject:time': 0.31; '[1]': 0.32; 'usually': 0.33; 'algorithms.': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'case,': 0.34; 'requirements': 0.34; 'received:google.com': 0.34; 'lists': 0.34; 'acceptable': 0.35; 'but': 0.36; 'being': 0.36; 'url:org': 0.36; 'list,': 0.36; 'smaller': 0.36; 'quite': 0.37; 'turn': 0.37; 'subject:: ': 0.37; 'someone': 0.38; 'pm,': 0.39; 'url:en': 0.39; 'enough': 0.39; 'performance': 0.39; 'seem': 0.39; 'where': 0.40; 'called': 0.40; 'some': 0.40; 'your': 0.60; 'impact': 0.61; 'limit': 0.65; 'fact,': 0.67; 'account': 0.67; 'upper': 0.76; 'algorithm,': 0.84; 'chrisa': 0.84; 'complexity': 0.84; "it'd": 0.84; 'valid,': 0.84; 'to:none': 0.90; 'average': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=PhkwvVXy44cNYejrmWvjTjRimvD1kMz6lpW1eso8xGE=; b=ABnGvMkDr/k66+7JnyGYhaw6raSfm0h8pi8PhYez2S/4SEOSj/GXDcp3aO/gyGv5nQ kUC9gnsGAOZri5zWprogAarK5BRQWyimr9lzY8y4EUrqgPgaFm5hiITabTd+IZN5465y h5ARctVDPjjBppcKCqwCXf2ZPAt0ZlZbpfkbWu7lhmmiQAIjBMTdQqyjAFJu3aXNm4Pv 2OKLdFFXayAVOMQRqUoyHdEpSs6NNfmqutPlFQC4kMwBu+9vHBfpy5qou2fbEknBfat3 Uo9qKB9oTROSYP1Odd/UdPH/KrYJs+eentjgMo33WtmcUHX3CESaSzH8nEJiRto/WAxH qIQg==
MIME-Version 1.0
X-Received by 10.50.66.146 with SMTP id f18mr33219065igt.14.1432196741880; Thu, 21 May 2015 01:25:41 -0700 (PDT)
In-Reply-To <555d8ae3$0$11095$c3e8da3@news.astraweb.com>
References <9ceklad15llnv3npejq9iuh91soci8aeqo@4ax.com> <555b0621$0$2753$c3e8da3$76491128@news.astraweb.com> <mjff5g$met$1@dont-email.me> <555b6db8$0$12996$c3e8da3$5496439d@news.astraweb.com> <adoplatr4fq8nssa9s2pk3bbpmhtkdk775@4ax.com> <555d8ae3$0$11095$c3e8da3@news.astraweb.com>
Date Thu, 21 May 2015 18:25:41 +1000
Subject Re: Slices time complexity
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.194.1432196751.17265.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432196751 news.xs4all.nl 2832 [2001:888:2000:d::a6]:49924
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91002

Show key headers only | View raw


On Thu, May 21, 2015 at 5:35 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>> You don't need huge. On any algorithm where slices are being used you
>> will have to account for the linear complexity. You seem to be
>> dismissive of this fact, but it can have tremendous performance
>> implications, since it can turn a linear algorithm into a quadratic
>> one just like that.
>
> Sure. And for small enough N, everything is fast.
>
> There's a sorting algorithm, usually called "Bozo sort", which shuffles the
> list, then checks whether it is sorted. If not, it shuffles it again, until
> it is sorted. Bozo sort is a *terrible* algorithm, with no upper limit to
> the worst case, and O(N!) for the average case. And yet, with small lists
> (say, five items) the performance is acceptable if your requirements are
> low.

A less ridiculous, but equally valid, comparison is with
multiplication algorithms. A while ago someone asked about what Python
uses, and on learning that CPython uses Karatsuba [1], suggested that
some other algorithm (I don't remember which) had better asymptotic
complexity. Downside: It'd be slower for smaller numbers, and the
complexity cost of an additional cutoff ("use grade-school up to X,
then Karatsuba up to Y, then Fuerer's") would also negatively impact
performance overall. Grade-school arithmetic is O(N*N) which looks
terrible... but for smallish numbers, its performance is quite
adequate.

ChrisA

[1] https://en.wikipedia.org/wiki/Karatsuba_algorithm

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Slices time complexity Mario Figueiredo <marfig@gmail.com> - 2015-05-18 20:23 +0100
  Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-19 05:36 +1000
    Re: Slices time complexity Mario Figueiredo <marfig@gmail.com> - 2015-05-18 20:49 +0100
      Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-19 06:04 +1000
  Re: Slices time complexity Todd <toddrjen@gmail.com> - 2015-05-18 21:42 +0200
  Re: Slices time complexity Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-18 13:49 -0600
    Re: Slices time complexity Fabien <fabien.maussion@gmail.com> - 2015-05-18 21:54 +0200
      Re: Slices time complexity Todd <toddrjen@gmail.com> - 2015-05-18 22:23 +0200
    Re: Slices time complexity Mario Figueiredo <marfig@gmail.com> - 2015-05-18 22:04 +0100
      Re: Slices time complexity Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-18 22:38 +0100
      Re: Slices time complexity Terry Reedy <tjreedy@udel.edu> - 2015-05-18 19:04 -0400
    Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-18 19:20 -0700
      Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 15:13 +1000
        Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-18 22:33 -0700
          Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-19 10:12 +0300
            Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 18:16 +1000
              Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-19 11:39 +0300
                Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-19 18:50 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-19 12:35 +0300
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 23:44 +1000
                Re: Slices time complexity Christian Gollwitzer <auriocus@gmx.de> - 2015-05-20 23:54 +0200
                Re: Slices time complexity Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-19 23:00 +1200
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 11:47 +1000
                Re: Slices time complexity Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-20 08:07 -0400
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 22:42 +1000
                Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-19 23:24 +1000
                Re: Slices time complexity Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-20 12:31 +1200
                Re: Slices time complexity Ben Finney <ben+python@benfinney.id.au> - 2015-05-20 10:42 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-20 07:24 +0300
                Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-19 21:30 -0700
                Re: Slices time complexity Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-20 06:06 +0100
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 15:57 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-20 09:17 +0300
                Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-19 23:23 -0700
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-20 09:46 +0300
                Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-20 00:03 -0700
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-20 10:45 +0300
                List semantics [was Re: Slices time complexity] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 17:23 +1000
                Re: List semantics [was Re: Slices time complexity] Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-20 20:54 +1200
                Re: List semantics [was Re: Slices time complexity] Ned Batchelder <ned@nedbatchelder.com> - 2015-05-20 04:08 -0700
                Re: List semantics [was Re: Slices time complexity] Terry Reedy <tjreedy@udel.edu> - 2015-05-20 14:42 -0400
                Re: List semantics [was Re: Slices time complexity] Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-21 11:06 +1200
                Re: List semantics [was Re: Slices time complexity] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-21 12:10 +1000
                Re: Slices time complexity "Bartc" <bartc@freeuk.com> - 2015-05-20 10:56 +0100
                Re: Slices time complexity Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-20 10:16 +0100
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-21 15:19 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-21 09:20 +0300
                Re: Slices time complexity bartc <bart4858@gmail.com> - 2015-05-21 06:34 -0700
                Re: Slices time complexity MRAB <python@mrabarnett.plus.com> - 2015-05-21 17:50 +0100
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-22 03:16 +1000
                Re: Slices time complexity bart4858@gmail.com - 2015-05-21 12:48 -0700
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 12:26 +1000
                Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-20 12:36 +1000
                Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-19 20:02 -0700
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 21:43 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-19 18:59 +0300
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 03:46 +1000
                Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-20 04:12 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-19 21:19 +0300
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 10:43 +1000
                Re: Slices time complexity Marko Rauhamaa <marko@pacujo.net> - 2015-05-20 07:30 +0300
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 15:33 +1000
                Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 15:58 +1000
                Re: Slices time complexity Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-19 15:18 +0100
            Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-19 04:46 -0700
              Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-19 05:14 -0700
          Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 18:19 +1000
            Re: Slices time complexity Rustom Mody <rustompmody@gmail.com> - 2015-05-19 04:41 -0700
  Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-19 19:45 +1000
    Re: Slices time complexity Serhiy Storchaka <storchaka@gmail.com> - 2015-05-19 13:15 +0300
    Re: Slices time complexity Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-19 12:09 +0100
    Re: Slices time complexity "Bartc" <bartc@freeuk.com> - 2015-05-19 15:52 +0100
      Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 03:07 +1000
        Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-20 03:19 +1000
        Re: Slices time complexity Mario Figueiredo <marfig@gmail.com> - 2015-05-20 20:51 +0100
          Re: Slices time complexity Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-20 14:33 -0600
          Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-21 06:35 +1000
          Re: Slices time complexity Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-20 21:47 +0100
            Re: Slices time complexity Mario Figueiredo <marfig@gmail.com> - 2015-05-20 22:23 +0100
          Re: Slices time complexity Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-21 17:35 +1000
            Re: Slices time complexity Chris Angelico <rosuav@gmail.com> - 2015-05-21 18:25 +1000
    Re: Slices time complexity Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-19 09:15 -0600
    Re: Slices time complexity Serhiy Storchaka <storchaka@gmail.com> - 2015-05-19 22:51 +0300

csiph-web