all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to delete all nil properties from a plist?
Date: Thu, 06 Aug 2015 01:30:50 +0200	[thread overview]
Message-ID: <87mvy5nwid.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.7864.1438816202.904.help-gnu-emacs@gnu.org

Emanuel Berg <embe8573@student.uu.se> writes:

> "Pascal J. Bourguignon" <pjb@informatimago.com>
> writes:
>
>>>> This is horrible. Again, you can't prevent
>>>> yourself writing O(n²) code when O(n) would
>>>> do perfectly.
>>>
>>> Is it `append' or `butlast' that is linear as well?
>>
>> Both.
>
> OK!
>
> It would be useful to have a list with the time
> complexities of all the list operators. Because here
> (with `append' and `butlast') it isn't clear from what
> those functions do that they are linear. On the
> contrary: if we think of an open bike chain in
> a workshop, then to put another link at either end
> isn't linear, it is O(1), as is removing a link from
> either end.

Depends on what end of the chain you hold.

To make it easier, imagine this bike chain, but 10 km long, obviously,
you have one end in hand, and the other is stored three workshop beyond.
To find this other end, you have to go thru each link.  O(n).


There is no such list of complexities because:

1- it is obvious. When you've studied lisp, you have implemented most of
   them.

2- in most cases, the algorithms are not specified, so an implementation
   would be free to provide something more efficient, if it was possible.

3- there is some expectations on the part of CL users, and sometimes an
   implementation may use a worse algorithm. Then its users will
   complain and a better algorithm is implemented.  So mostly all
   implementations have similar time and space complexities.

Nonetheless, if you find it would be useful to have such a list, you can
establish it.

There are 636 functions in CL. 

If you research the best algorithms for each, noting the time and space
complexities, and finding what complexities and (approximate) actual
factors each implementation provide, for 2 functions each day, you will
be done in less than a year.


> So I think my algorithm is actually linear (but not
> the implementation you saw) if only I replaced those
> functions with manually re-linking the items (because
> if the list is built manually, the last item could be
> stored, and then linked further to in constant time
> which would imply appending to the list as that item
> is already part of the list, the last part) - I don't
> know how to do that right now, perhaps I'll be back if
> I don't find something else to do...

Absolutely.

Also, notice that doing that, or consing onto the beginning of the list
and calling nreverse when you're done are equivalent time-complexity
wise.  There may be some difference re: cache in actual contemporaneous
computers but it can be seen only on very long lists.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


  parent reply	other threads:[~2015-08-05 23:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-01 22:03 How to delete all nil properties from a plist? Marcin Borkowski
2015-08-01 22:11 ` Marcin Borkowski
2015-08-02  1:32   ` Emanuel Berg
     [not found]   ` <mailman.7753.1438479312.904.help-gnu-emacs@gnu.org>
2015-08-02  1:36     ` Pascal J. Bourguignon
2015-08-02  1:50       ` Emanuel Berg
2015-08-02  3:55       ` Rusi
2015-08-02 16:21         ` Pascal J. Bourguignon
     [not found]       ` <mailman.7754.1438480361.904.help-gnu-emacs@gnu.org>
2015-08-02 16:24         ` Pascal J. Bourguignon
2015-08-05 23:08           ` Emanuel Berg
     [not found]           ` <mailman.7864.1438816202.904.help-gnu-emacs@gnu.org>
2015-08-05 23:30             ` Pascal J. Bourguignon [this message]
2015-08-05 23:49               ` Emanuel Berg
2015-08-06  0:30               ` Emanuel Berg
2015-08-06  1:05                 ` John Mastro
2015-08-06  1:07                   ` John Mastro
     [not found]               ` <mailman.7867.1438818687.904.help-gnu-emacs@gnu.org>
2015-08-06  2:32                 ` Pascal J. Bourguignon
2015-08-07 22:21                   ` Emanuel Berg
     [not found]               ` <mailman.7869.1438821124.904.help-gnu-emacs@gnu.org>
2015-08-06  2:40                 ` Pascal J. Bourguignon
2015-08-07 22:32                   ` Emanuel Berg
     [not found]                   ` <mailman.7963.1438986782.904.help-gnu-emacs@gnu.org>
2015-08-08  3:56                     ` Pascal J. Bourguignon
2015-08-09  1:34                       ` Emanuel Berg
     [not found]                       ` <mailman.7996.1439084206.904.help-gnu-emacs@gnu.org>
2015-08-09  2:18                         ` Pascal J. Bourguignon
2015-08-09  2:28                           ` Emanuel Berg
     [not found] ` <mailman.7749.1438467076.904.help-gnu-emacs@gnu.org>
2015-08-01 23:46   ` Pascal J. Bourguignon
     [not found] <mailman.7748.1438466648.904.help-gnu-emacs@gnu.org>
2015-08-01 23:43 ` Pascal J. Bourguignon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvy5nwid.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.