[Python-ideas] Extremely weird itertools.permutations

Tim Peters tim.peters at gmail.com
Tue Oct 15 03:40:00 CEST 2013


[MRAB]
> I can see that one disadvantage of my algorithm is that the worst-case
> storage requirement is O(n^2) (I think). This is because the set of
> first items could have N members, the set of second items could have
> N-1 members, etc. On the other hand, IMHO, the sheer number of
> permutations will become a problem long before the memory requirement
> does! :-)

My rewrite is O(N) space (best and worst cases).  I _think_ yours is
too, but I understand my rewrite better by now ;-)

Each element of the iterable appears in exactly one ENode:  the
`ehead` list is a partitioning of the input iterable.


More information about the Python-ideas mailing list