ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
RE: Surprising (for me) benchmark results...
by Brian Quinlan other posts by this author
May 2 2001 6:04PM messages near this date
Re: Surprising (for me) benchmark results... | RE: Surprising (for me) benchmark results...
>  There are O(N) sorting algorithms??  I thought that was restricted to
>  quantum computation.

Actually, there are O(N) sorting algorithms. Counting sort is O(N). The
algorithm is simple but only works in (small) descrete element spaces. The
following example works with integers:

def sort( A, k ):
    b = []
    c = []
    for i in range(k):
        c.append(0)

    for j in A:
        c[j] += 1

    for i in range(len(c)):
        b += [i] * c[i]

    return b


print sort( [1,2,2,2,2,5,4,3,2,2,2,5], 6 )
> >> [1, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5, 5]

BTW, this isn't an efficient implementation so don't use it or anything :-)


-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
John J. Lee
Daniel Berln
John J. Lee
Brian Quinlan
John J. Lee
Daniel Berlin
John J. Lee

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved