[erlang-questions] Can I do the same with a fold easily

ok@REDACTED ok@REDACTED
Mon Oct 19 04:54:41 CEST 2015


"Éric Pailleau" <eric.pailleau@REDACTED>

> A number cannot be both even and odd, so simply take odd numbers in a
> variable O from list L , even numbers will be L -- O.

Here we run into the question "what does BEST mean?"

Now Xs -- Ys cannot assume anything about the contents of Xs or Ys,
other than them both being well formed lists.  So while it *could*
be implemented in O(|Xs|+|Ys|+|Xs|lg|Ys|) time by building some kind
of balanced search tree from Ys, or even better by building some
kind of hashed set, the cost of building the supporting data structure
would likely be worse than the cost of traversing L twice or using
lists:partition/2.






More information about the erlang-questions mailing list