Professional Documents
Culture Documents
Review Questions #20 - Top Hat
Review Questions #20 - Top Hat
Review Questions #20 - Top Hat
Drag and drop options on the right-hand side and submit. For keyboard navigation... SHOW MORE
Monte Carlo
Correct Answers:
Drag and drop options on the right-hand side and submit. For keyboard navigation... SHOW MORE
Las Vegas
Correct Answers:
A programmer decides to use the seventh and eighth digits of ten-digit phone numbers as a source of random
numbers in the range 0 thru 99. (That is, she uses the YY portion of a phone number N = XXXXXXYYXX as a two-digit
number.) Which TWO arithmetic expressions below can be used to accomplish this? Let / denote integer-division and
% denote modulo.
Select one or more answers and submit. For keyboard navigation... SHOW MORE
a (N % 100) / 100
b (N % 1000) / 1000
c (N % 1000) / 10000
d (N % 10000) / 100
e (N % 10000) / 1000
f (N / 100) % 100
g (N / 1000) % 1000
h (N / 1000) % 10000
i (N /10000) % 100
j (N /10000) % 1000
Correct Answers:
d - (N % 10000) / 100
f - (N / 100) % 100
Which are true of the Universally Unique Identifier (UUID), sometimes used as a source of random numbers?
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
Correct Answer:
d - All of the above
Which of the following criteria are necessary and sufficient for a Linear Congruential Generator
- with non-zero b - to have a full period m (i.e. all m numbers in 0 ... m-1 are obtained
before the cycle repeats itself)?
Select one or more answers and submit. For keyboard navigation... SHOW MORE
Correct Answers:
b - a-1 is divisible by 4 if m is divisible by 4
c - a-1 is divisible by all prime factors of m
Creating a Permutation
Review
What is the time complexity of the method developed in class to create a random permutation of n elements?
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
a Θ(log n)
b Θ(n)
c Θ(n log n)
d Θ(n^2)
e Θ(2^n)
f Θ(n!)
Correct Answer:
b - Θ(n)
Correct Answer:
1.0
Which are true of the time and space complexity of a Treap (Randomized BST)?
Select one or more answers and submit. For keyboard navigation... SHOW MORE
Correct Answers:
a - Its average case time for Search is O(log n)
b - Its average case time for Insert is O(log n)
c - Its average case time for Delete is O(log n)
e - Its worst case time for Search is O(n)
f - Its worst case time for Insert is O(n)
g - Its worst case time for Delete is O(n)
h - Its worst case space is O(n)
Correct Answer:
12.0
Treap Concepts
Review
Which of the following are true of the data structure Treap (randomized BST)?
Multiple answers: Multiple answers are accepted for this question
Select one or more answers and submit. For keyboard navigation... SHOW MORE
c Each node in Treap has a PRIORITY which represents the number of descendant nodes
e The Inorder Traversal (familiar from BST) yields a sorted order of the KEYS when applied to a Treap
Correct Answers:
a - The word Treap is a hybrid of Tree and Heap
b - Each node in a Treap has a KEY used for searching
e - The Inorder Traversal (familiar from BST) yields a sorted order of the KEYS when applied to a Treap
Correct Answer:
13.0
Show Submitted Answer Hide Correct Answer Check My Answer
At the end of June, a bunch of customers all having birthdays in July enter a bakery to order cakes for their July
birthday celebrations. How many such customers must there be so that there is at least a 50% chance (>= .5
probability) that at least two of them were born on the same day in July (ignore the year). Assume that there are no
other customers in the store and that there are no concerns about social distancing etc.
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
a 5
b 7
c 9
d 11
e 13
f 15
g 17
h 19
i 21
j 23
Correct Answer:
b-7
Select one or more answers and submit. For keyboard navigation... SHOW MORE
Correct Answers:
b - all numbers 1 thru m-1
c - period of maximum length m/4
Select one or more answers and submit. For keyboard navigation... SHOW MORE
Correct Answers:
a - when p is prime then a^(p-1) = 1 mod p
b - when p is prime then a^p = a mod p
Suppose that the function rand() returns a random decimal in the interval [0, 1). Which composite function should
be used to simulate the total of a pair of dice?
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
a floor(12 rand())
b ceil(12 rand())
c 2 floor(6 rand())
d 2 ceil(6 rand())
Correct Answer:
g - ceil(6 rand()) + ceil(6 rand())
Suppose that the function rand() returns a random decimal between 0 and 1. What composite function should be
used to generate pairs of random numbers all inside the square around the circle of diameter 2 centered at the
origin (like in the picture in the slides)
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
a x = rand() + 1, y = rand() + 1
b x = rand() + 2, y = rand() + 2
c x = rand() - 2, y = rand() - 2
d x = 2rand(), y = 2rand()
e x = 2rand() + 1, y = 2rand() + 1
f x = 2rand() - 1, y = 2rand() - 1
Correct Answer:
f - x = 2rand() - 1, y = 2rand() - 1
Select one or more answers and submit. For keyboard navigation... SHOW MORE
a It uses a Variable-Size Decrease-and-Conquer design technique
Correct Answers:
b - Its average case time complexity is Θ(log n)
d - It can be implemented iteratively or recursively
Select one or more answers and submit. For keyboard navigation... SHOW MORE
Assume you have an array, indexed from 0 to 9, with the numbers 1 4 9 16 25 36 49 64 81 100. You are searching for
the key 100. Your random number generator gives the following numbers in range [ 0,9] to be used as indexes: 6 3 1 5
7 9 0 0 5 2 8 1 9 6 4 2 7. You consider those random numbers in order, ignoring those that have already been used or
are outside the currently relevant range. How many key comparisons (i.e. comparing the search key of 100 against
data in the array) will be required until you find the key 100? (Assume that <, =, or > can be determined with with a
single key comparison.)
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
a 1
b 2
c 3
d 4
e 5
f 6
g 7
h 8
i 9
j 10
Correct Answer:
c-3
Explanation
Use random numbers 6, 7, 9
Randomized Estimation of Pi
Review
Which inequality should be used to determine if points fall within the circle of diameter 2 centered at the origin?
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
What estimate of pi would our randomized algorithm compute if our source of random numbers gives the following
10 pairs of points (x,y):
-0.8322,-0.4899
-0.5224,0.5117
0.7583,0.8756
0.7782,-0.8260
0.2597,0.6354
-0.0072,-0.6112
-0.5218,-0.3444
-0.9582,0.9481
-0.0192,-0.2660
0.9353,-0.2829
Select an answer and submit. For keyboard navigation, use the up/down arrow keys to select an answer.
a 2.2
b 2.4
c 2.6
d 2.8
e 3.0
f 3.2
g 3.4
h 3.6
i 3.8
j 4.0
Correct Answer:
d - 2.8