# 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.

## Presentation on theme: "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."— Presentation transcript:

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 44 55 66  22 33 10  JJ Value88 99 23450189Array index67 99 22 random integer = 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 44 55 66  99 33 10  JJ Value88 22 23450189Array index67 55 33 random integer = 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 44 33 66  99 55 10  JJ Value88 22 23450189Array index67 JJ 44 random integer = 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 JJ 33 66  99 55 10  44 Value88 22 23450189Array index67 44 33 random integer = 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 JJ 44 66  99 55 10  33 Value88 22 23450189Array index67 88 66 random integer = 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 JJ 44 88  99 55 10  33 Value66 22 23450189Array index67 33 77 random integer = 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 JJ 44 88 33 99 55 10  77 Value66 22 23450189Array index67 10  66 random integer = 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 JJ 44 88 33 99 55 66 77 Value10  22 23450189Array index67 77 22 random integer = 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 JJ 44 88 33 99 55 66 22 Value10  77 23450189Array index67 66 random integer = 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 JJ 44 88 33 99 55 66 22 Value10  77 23450189Array index67 22 random integer = 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 JJ 44 88 33 99 55 66 22 Value10  77 23450189Array index67

Download ppt "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."

Similar presentations