Download presentation
Presentation is loading. Please wait.
Published byNyla Nichols Modified over 10 years ago
1
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i 44 55 66 22 33 10 JJ Value88 99 23450189Array index67 99 22 random integer = 7
2
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i 44 55 66 99 33 10 JJ Value88 22 23450189Array index67 55 33 random integer = 3
3
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i 44 33 66 99 55 10 JJ Value88 22 23450189Array index67 JJ 44 random integer = 9
4
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 33 66 99 55 10 44 Value88 22 23450189Array index67 44 33 random integer = 9
5
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 66 99 55 10 33 Value88 22 23450189Array index67 88 66 random integer = 6
6
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 88 99 55 10 33 Value66 22 23450189Array index67 33 77 random integer = 9
7
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 88 33 99 55 10 77 Value66 22 23450189Array index67 10 66 random integer = 8
8
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 88 33 99 55 66 77 Value10 22 23450189Array index67 77 22 random integer = 9
9
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 88 33 99 55 66 22 Value10 77 23450189Array index67 66 random integer = 8
10
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 88 33 99 55 66 22 Value10 77 23450189Array index67 22 random integer = 9
11
Shuffle an Array Shuffle a deck of cards. n In i th iteration, choose a random element from remainder of deck and put at index i. – choose random integer r between i and N-1 – swap values in positions r and i JJ 44 88 33 99 55 66 22 Value10 77 23450189Array index67
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.