1

We have to find all possible permutations of an array WITHOUT making a copy of the array. I know how to do it recursively using lists and I'm assuming we need to do it recursively for arrays as well. My idea was to swap the elements in the array So something like this:

for i in range(0, len(A)):
    A(i,i+1) = A(i+1,i)

But I do not know how to make a recursive function using arrays. Especially since the length of the array is unknown and swapping is using 2 elements only.

Jessy White
  • 297
  • 1
  • 3
  • 13
  • What kind of array? [These](https://docs.python.org/2/library/array.html)? [Numpy](https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.array.html)? – Two-Bit Alchemist Feb 25 '16 at 16:39
  • Like for example A=('b',[1,2,3,4,5]), we did not learn Numpy yet. – Jessy White Feb 25 '16 at 16:40
  • That's not an array; that's a tuple. I'm just trying to figure out why you're distinguishing between arrays and lists. Also since this appears to be homework/for a class, do you have any other restrictions, like you can't use certain things in the standard library? – Two-Bit Alchemist Feb 25 '16 at 16:42
  • No other restrictions but we should use 'from array import array'. We want to use arrays because in arrays we are able to swap the letters without making a copy of the list so it uses less space and memory, from what I understood. – Jessy White Feb 25 '16 at 16:49
  • Possible duplicate of [How to generate all permutations of a list in Python](http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python) – Prune Feb 25 '16 at 22:33

0 Answers0