help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easy to add with push but not to the end of a list


From: Emanuel Berg
Subject: Re: Easy to add with push but not to the end of a list
Date: Tue, 29 Nov 2022 10:54:17 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Heime wrote:

>> Programming is somewhere between engineering and craft.
>> In these realms, you usually try to think about what tools
>> are appropriate for a job.
>
> Programming has got nothing to do with engineering or craft.

Unheard of :O

> Stefan mentioned using reverse to put it into another list.
> If needed the execution time would not be much different
> than actually place new elements at end of list.

I think the lists has to be double linked for it to be
theoretically possible to push-last in constant or O(1) time,
otherwise, with our car/cdr lists that are one-directional or
single linked, the execution time of such an operation will be
proportional to the length of the list, i.e. the number of
elements, so it'll be linear time or O(n) where n is the
number of elements of a conceptual/arbitrary list.

But also in practice! Only for you to notice it, i.e.
the difference between O(1) and O(n), the list probably has to
be pretty long, so a large n then ...

Start testing ...

> Nobody will get hurt. Just inefficient for long lists or for
> large number of calls.

That's exactly right.

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]