/
Shuffle an Array Shuffle an Array

Shuffle an Array - PowerPoint Presentation

cheryl-pisano
cheryl-pisano . @cheryl-pisano
Follow
400 views
Uploaded On 2016-07-12

Shuffle an Array - PPT Presentation

Shuffle a deck of cards In i th iteration choose a random element from remainder of deck and put at index i choose random integer r between i and N1 swap values in positions r and i 4 ID: 401668

index random deck array random index array deck shuffle choose integer

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Shuffle an Array" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

4

5

6

7

2

3

10

J

Value

8

9

2

3

4

5

0

1

8

9

Array index

6

7

9

2

random integer = 7Slide2

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

4

5

6

7

9

3

10

J

Value

8

2

2

3

4

5

0

1

8

9

Array index

6

7

5

3

random integer = 3Slide3

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

4

3

6

7

9

5

10

J

Value

8

2

2

3

4

5

0

1

8

9

Array index

6

7

J

4

random integer = 9Slide4

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

3

6

7

9

5

10

4

Value

8

2

2

3

4

5

0

1

8

9

Array index

6

7

4

3

random integer = 9Slide5

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

6

7

9

5

10

3

Value

8

2

2

3

4

5

0

1

8

9

Array index

6

7

8

6

random integer = 6Slide6

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

8

7

9

5

10

3

Value

6

2

2

3

4

5

0

1

8

9

Array index

6

7

3

7

random integer = 9Slide7

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

8

3

9

5

10

7

Value

6

2

2

3

4

5

0

1

8

9

Array index

6

7

10

6

random integer = 8Slide8

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

8

3

9

5

6

7

Value

10

2

2

3

4

5

0

1

8

9

Array index

6

7

7

2

random integer = 9Slide9

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

8

3

9

5

6

2

Value

10

7

2

3

4

5

0

1

8

9

Array index

6

7

6random integer = 8Slide10

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

8

3

9

5

6

2

Value

10

7

2

3

4

5

0

1

8

9

Array index

6

7

2random integer = 9Slide11

Shuffle an Array

Shuffle a deck of cards.In ith iteration, choose a random element from remainder of deck and put at index i.choose random integer r between i and N-1swap values in positions r and i

J

4

8

3

9

5

6

2

Value

107

2

3

4

5

0

1

8

9

Array index

6

7