help with random permutations problem

Правка en2, от rsFalse, 2016-10-29 00:59:45

Hello,
I had a problem: make sequence of random permutations which elements do not occur in same positions. E.g. I have list ('a', 'b', 'c', 'd'). I randomly generate permutation, say 'a d b c', then next permutation, say 'd c a b, then next permutation can not start with 'a' and 'd', because these elements occurs in first or second sequence on same position.
My algorithm is slow: I repeat to generate random (with Fisher-Yates shuffle) permutation and check each element if it not occur in previous sequences (I used 2D array). How to determine what is the complexity of my algorithm?
How to solve problem faster?

Теги permutation

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский rsFalse 2016-10-29 00:59:45 5 Tiny change: ' say 'd c b a', then nex' -> ' say 'd c a b, then nex'
en1 Английский rsFalse 2016-10-29 00:57:30 734 Initial revision (published)