MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: List of multiple elements

  • To: mathgroup at
  • Subject: [mg112144] Re: List of multiple elements
  • From: Ray Koopman <koopman at>
  • Date: Thu, 2 Sep 2010 02:30:28 -0400 (EDT)
  • References: <i5d019$bs8$> <i5g0hu$gos$>

On Sep 1, 3:29 am, Raffy <adra... at> wrote:
> I'm pretty sure the solution I posted above is the fastest unless
> more assumptions are made.
> Most of the solutions listed require multiple searches over the
> elements or require sorting neither of which are necessary.
> dup3[v_] := Join @@ (ConstantArray[#1, #2 - 1] & @@@ Tally[v]);
> v = RandomInteger[{1, 100}, 10000000];
> dup3[v]; // Timing ==> 0.031
> sordups[v]; // Timing ==> 2.87

I agree that if speed matters then any code using Split at Sort[...]
should be reconsidered. In the present case the determiners seem to
be the length of the list, the number of different values in it, and
the user's requirements regarding the ordering of the results. If
ordering does not matter then dup3 will be faster for longer lists
with fewer different values, and sordups will be faster for shorter
lists with more different values. For lists with less than 10^4
elements, the critical ratio of number of different values to total
list length seems to be in the neighborhood of 10%. For lists with
more than 10^4 elements, sordups slows suddenly, suggesting to me that
there may be a change in the kernel implementation for longer lists.

  • Prev by Date: Re: coordinates in LogLogPlots
  • Next by Date: Difficult constrained optimization problem
  • Previous by thread: Re: List of multiple elements
  • Next by thread: 2 dimensional engineering problem