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


Groups > comp.lang.python > #101631

Re: How to remove item from heap efficiently?

From Robin Becker <robin@reportlab.com>
Newsgroups comp.lang.python
Subject Re: How to remove item from heap efficiently?
Date 2016-01-13 16:40 +0000
Message-ID <mailman.112.1452703239.13488.python-list@python.org> (permalink)
References (5 earlier) <CACs7g=AuW8UTVS+SRM-bG=-Ne18W5VLt2CfTDjS0i1cH2qwtpw@mail.gmail.com> <FF3CA092-4D74-4C25-8C7A-C20D54C69657@gmail.com> <5695276A.2020101@mail.de> <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> <CACs7g=B-kNiqB5p1Zs3dyp1vW7P=K4bwG_HzGkX_83Z7Y6uHMg@mail.gmail.com>

Show all headers | View raw


On 13/01/2016 15:34, srinivas devaki wrote:
> On Wed, Jan 13, 2016 at 4:50 PM, Cem Karan <cfkaran2@gmail.com> wrote:
>>
>> Is that so?  I'll be honest, I never tested its asymptotic performance, I just assumed that he had a dict coupled with a heap somehow, but I never looked into the code.
>>
>
> I have just tested the code, the aymptotic performance is O(log(n))
> for all operations. Infact the code is very simple to understand,
> technically the heapdict class is composed of a dict and heap, each element of
> heap is a mutable list and dict stores references to that mutable list,
> so that a specific element can be deleted in O(log(n))
>
is this true? I looked at https://wiki.python.org/moin/TimeComplexity and it 
says that dict.get which I assume is used for accessing the heapq delete point 
can be large (the average time is O(1), but amortized over a lot of accesses can 
be O(n)). Apparently the history of sets/gets can affect individual times quite 
a lot. I seem to remember there was some kind of hashing attack against python 
dicts that would use up large amounts of time, but I guess that's now fixed.
-- 
Robin Becker

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


Thread

Re: How to remove item from heap efficiently? Robin Becker <robin@reportlab.com> - 2016-01-13 16:40 +0000

csiph-web