Bingo Example: Design (Random Distinct Numbers Algorithm)

Slides:



Advertisements
Similar presentations
Tutorial 8 CSI 2132 Database I. Exercise 1 Both disks and main memory support direct access to any desired location (page). On average, main memory accesses.
Advertisements

Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Tutorial #6 PseudoCode (reprise)
Probability theory and average-case complexity. Review of probability theory.
Computability and Complexity 20-1 Computability and Complexity Andrei Bulatov Random Sources.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
CMSC 250 Discrete Structures Summation: Sequences and Mathematical Induction.
ASC Program Example Part 3 of Associative Computing Examining the MST code in ASC Primer.
Dueling Algorithm. Data Structures List of potential candidates R = rightmost element of that list N = new element RN.
Backtracking.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
1. On a math test, 12 students earned an A
Probability Distributions BINOMIAL DISTRIBUTION. Binomial Trials There are a specified number of repeated, independent trials There are a specified number.
Data Structures & Algorithms
1 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
1D Arrays and Random Numbers Artem A. Lenskiy, PhD May 26, 2014.
Hashing. Search Given: Distinct keys k 1, k 2, …, k n and collection T of n records of the form (k 1, I 1 ), (k 2, I 2 ), …, (k n, I n ) where I j is.
Clue Paths. Memory Alias Review Remember that it’s possible for two unique variables to point to the same memory location myList MyClass mc 0x100 someFn.
Probability theory and average-case complexity. Review of probability theory.
Stat 100 Mar. 27. Work to Do Read Ch. 3 and Ch. 4.
Linked Data Structures
Recursion Version 1.0.
Lecture 5 of Computer Science II
A brief comparison of integer and double representation
BackTracking CS255.
CSCI 210 Data Structures and Algorithms
Recitation 13 Searching and Sorting.
CSCE 411 Design and Analysis of Algorithms
S2 Chapter 6: Populations and Samples
Introduction to Algorithms
Stack Data Structure, Reverse Polish Notation, Homework 7
CSc 110, Spring 2018 Lecture 32: Sets and Dictionaries
Cookies BIS1523 – Lecture 23.
Random numbers Taken from notes by Dr. Neil Moore
Searching CSCE 121 J. Michael Moore.
Developing Loops from Invariants
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Advanced Sorting Methods: Shellsort
Sorting CSCE 121 J. Michael Moore
Graphing Inequalities.
Hidden Markov Models Part 2: Algorithms
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Hashing.
Resolving collisions: Open addressing
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Heaps Chapter 10 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates two.
Heaps Chapter 10 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates two.
3.4 Push-Relabel(Preflow-Push) Maximum Flow Alg.
Graphing Inequalities.
Sorting … and Insertion Sort.
Heaps Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates.
Linked List Insert After
A General Backtracking Algorithm
Heaps Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates.
CSCE 411 Design and Analysis of Algorithms
Linked List Configurations
15-110: Principles of Computing
Bingo Example: Design (Fill Card Algorithm)
Data Structures Unsorted Arrays
Bingo Example: Analysis
Application: Algorithms
Sorting We may build an index on the relation, and then use the index to read the relation in sorted order. May lead to one disk block access for each.
Graphing Inequalities.
Biologically Inspired Computing: Operators for Evolutionary Algorithms
CSC1401 Manipulating Pictures 2
Linked List Configurations
Heaps Chapter 10 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates two.
CSCE 411 Design and Analysis of Algorithms
CHAPTER 2.1 PROBABILITY DISTRIBUTIONS.
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Bingo Example: Design (Random Distinct Numbers Algorithm) J. Michael Moore CSCE 121

Random Number Generators Really pseudorandom number generator Given the same seed, it will always produce the same sequence of “random” values If you don’t know the seed, the choices seem random. Can give the same value two times in a row In C++, take remainder to get values in a specified range

Goal Fill container with n distinct numbers. If they didn’t have to be distinct, we’d just use the built in random number generator directly.

Build a Model Let’s do one based on how the random number generator works…

Brute Force Potential Infinite Loop! What if you always get the same random number? Possible if not Probable Assume maxVal contains the maximum value numToGet contains the number of values to get Start with empty container, vals While size of vals < numToGet candidate ← randomvalue from 1 to maxVal newVal ← true (assume candidate will work) For each item in vals if item equals candidate newVal ← false (candidate is already there) If newVal add candidate to vals Potential Infinite Loop!

Build a Different Model How do we actually draw numbers?

Alternative Idea Fill another container with all of the possible values to use Draw value and put in our container of distinct values gets removed from possible values Since we removed the value, the next time we get one, we won’t get a duplicate!

Draw No Infinite Loop! Assume Start with empty container, vals maxVal contains the maximum value numToGet contains the number of values to get Start with empty container, vals Load bag with values from 1 to maxVal While size of vals < numToGet index ← randomvalue that is any valid index for bag value ← bag[index] Remove value from bag Add value to vals No Infinite Loop!