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.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Mod arithmetic.
2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
Directions: Form into Teams (up to 7 team members) Clear your tables and move chairs against the wall Only 4 people will participate per iteration Four.
Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
SORTING Lecture 12B CS2110 – Spring InsertionSort 2 pre: b 0 b.length ? post: b 0 b.length sorted inv: or: b[0..i-1] is sorted b 0 i b.length sorted.
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Selection and Insertion Sort Mrs. C. Furman October 1, 2008.
Sorting Algorithms. Motivation Example: Phone Book Searching Example: Phone Book Searching If the phone book was in random order, we would probably never.
1 CSE1301 Computer Programming: Lecture 28 List Sorting.
CS 106 Introduction to Computer Science I 04 / 02 / 2008 Instructor: Michael Eckmann.
Binary Search Visualization i j.
1 L42 Collections (2). 2 OBJECTIVES  To use collections framework algorithms to manipulate  search  sort  and fill collections.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
How should a computer shuffle?. Intro - 2 Comp 122, Goal  Input: Given n items to shuffle (cards, …)  Output: Return some list of exactly those n items;
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
 Pearson Education, Inc. All rights reserved Arrays.
CS 106 Introduction to Computer Science I 04 / 07 / 2010 Instructor: Michael Eckmann.
Value Iteration 0: step 0. Insertion Sort Array index67 Iteration i. Repeatedly swap element i with.
THEORETICAL PROBABILITY - SIMPLE EVENTS OCCURING.
1 Object-Oriented Programming Using C++ CLASS 2. 2 Linear Recursion Summing the Elements of an Array Recursively Algorithm LinearSum(A, n): Input: An.
A Semantic Error in Google last weekend! Someone in Google typed an extra ‘/’ character into their URL List Link to CNN video report posted on Collab.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Countdown Math Competition
Probabilistic Analysis and Randomized Algorithm. Average-Case Analysis  In practice, many algorithms perform better than their worse case  The average.
Духовні символи Голосіївського району
Sorting: Selection Sort Damian Gordon. Sorting: Selection Sort OK, so we’ve seen a way of sorting that easy for the computer, now let’s look at a ways.
C Lecture Notes 1 Structures & Unions. C Lecture Notes Introduction Structures –Collections of related variables (aggregates) under one name Can.
Sorting and Shuffling Arrays CS 233G Intermediate C++ Programming for Games.
Partitioning in Quicksort n How do we partition the array efficiently? – choose partition element to be rightmost element – scan from right for smaller.
How to do a card trick.
Venn Diagrams For each Venn diagram insert the numbers 1 to 10 into the correct sections. 1. Multiples of 2 Multiples of or less Factors of 12 2.
6.NS.5 Integer War You will need: deck of cards
The Pigeonhole Principle
Card Shuffling How many perfect shuffles will return a full deck
Review # 2 Math 8.
Choose the best answer for each problem.
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
-5*6= -6*(-8)= 2*(-16)= 54*4= Agenda Ticket in the Door
Randomized Algorithms
Insertion Sort Array index Value Insertion sort.
I have… I have… Who has 3:40? Who has 12:20? I have… I have…
Randomized Algorithms
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 Array 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 Array 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 Array 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 Array 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 Array 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 Array 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 Array 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 Array 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 Array 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 Array 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 Array index67