Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.04; 'subject:Python': 0.06; 'dan': 0.09; 'cc:addr:python-list': 0.11; 'cc:name:python list': 0.16; 'experimented': 0.16; 'former,': 0.16; 'heap': 0.16; 'heap,': 0.16; 'latter,': 0.16; 'worst': 0.16; 'index': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'basically': 0.19; 'aug': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; "i've": 0.25; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'array': 0.29; 'message-id:@mail.gmail.com': 0.30; 'largest': 0.30; 'that.': 0.31; '(since': 0.31; 'probably': 0.32; 'good.': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'url:org': 0.36; 'should': 0.36; 'step': 0.37; 'pm,': 0.38; 'expensive': 0.39; 'highest': 0.39; "you're": 0.61; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'beat': 0.68 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:to :cc:content-type; bh=LVkNYF7kldqpgOjTMfLJkynJTEdFqaEBmnz2UmCMA/Y=; b=eWn3xQUaylQNk59k8TgSJHmetij6j+IUvUkBNbOcYmRAv2pIICUHxQwvLhI6it38qJ GgyjlAx0H8va5YuqDePbNVa2eYwXMSZxJPFmD/yXcbxJ3e3myVcDjt6NnJfycIERNRdN zVwfDkISYi6cDS4xsQI9QUgrqYa3tBYmNETNqWu8vougg2lyeNd/tiTm1VtbPqWHccib NoX8oIqkQgiqjh4sGLwoSb9u0gEaxn/F2mSiZpRHwDBt2YYfNsnvZE+52w21kVB8DuZk LiGsK7C3ZH4LFJLHYg8FJwdke07CJbOPabmOU5GrApg2QuUj/70wFV3Wk2PuKkSHuq5k sbrg== MIME-Version: 1.0 X-Received: by 10.152.198.195 with SMTP id je3mr39937360lac.59.1408490568573; Tue, 19 Aug 2014 16:22:48 -0700 (PDT) In-Reply-To: References: <51dfbe9b-f6e0-4532-bc2d-e7ce2fc282b5@googlegroups.com> <3fb3b4d1-a7e2-4912-a878-7d5e1798aee6@googlegroups.com> Date: Tue, 19 Aug 2014 16:22:48 -0700 Subject: Re: efficient partial sort in Python ? From: Dan Stromberg To: Chiu Hsiang Hsu Content-Type: text/plain; charset=UTF-8 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408490569 news.xs4all.nl 2867 [2001:888:2000:d::a6]:34113 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76622 On Tue, Aug 19, 2014 at 4:10 PM, Dan Stromberg wrote: > On Tue, Aug 19, 2014 at 4:05 PM, Dan Stromberg wrote: >> When you use heapq, are you putting all the values in the heap, or >> just up to n at a time (evicting the worst value, one at a time as you >> go)? If you're doing the former, it's basically a heapsort which >> probably won't beat timsort. If you're doing the latter, that should >> be pretty good. > > It just occurred to me that evicting the highest value each step of > the way might be expensive with a traditional heap (since the value at > the largest array index isn't necessarily the largest). I've > experimented with doing this using a treap a bit: > http://stromberg.dnsalias.org/~strombrg/treap/ You might try that. Or more directly relevant: http://stromberg.dnsalias.org/~strombrg/highest/