Review Questions #20 - Top Hat

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Exported for YONGYING MAI on Sat, 27 Aug 2022 02:05:18 GMT

Review Questions #20


Some questions may require basic online research and/or using a calculator, program, or spreadsheet for
computations.  

Monte-Carlo and Las Vegas (Prior Algorithms)


Review

Match each randomized algorithm with its classification

Drag and drop options on the right-hand side and submit. For keyboard navigation... SHOW MORE

Quicksort/Quickselect Pivot Las Vegas

Bloom Filter Monte Carlo

Bogo Sort Las Vegas

Rabin Closest Points Las Vegas

Rabin-Karp Strin-Matching Monte Carlo

Monte Carlo

Correct Answers:

Quicksort/Quickselect Pivot Las Vegas

Bloom Filter Monte Carlo

Bogo Sort Las Vegas

Rabin Closest Points Las Vegas


Rabin-Karp Strin-Matching Monte Carlo

Show Submitted Answer Hide Correct Answer Check My Answer

Monte-Carlo and Las Vegas (Current Algorithms)


Review

Match each randomized algorithm with its classification

Drag and drop options on the right-hand side and submit. For keyboard navigation... SHOW MORE

Randomized Min / Max Monte Carlo

Randomized Binary Search Las Vegas

Treap Las Vegas

Fermat Primality Testing Monte Carlo

Calculating Pi From Unit Circle Monte Carlo

Las Vegas

Correct Answers:

Randomized Min / Max Monte Carlo

Randomized Binary Search Las Vegas

Treap Las Vegas

Fermat Primality Testing Monte Carlo

Calculating Pi From Unit Circle Monte Carlo


Show Submitted Answer Hide Correct Answer Check My Answer

Random Number From Phone Number


Review

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.

Multiple answers: Multiple answers are accepted for this question

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

Show Submitted Answer Hide Correct Answer Check My Answer

Universally Unique Identifier (UUID)


Review

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.

a UUID consists of 128 bits

b UUID consists of 16 octets

c UUID consists of 32 hexadecimal digits

d All of the above

Correct Answer:
d - All of the above

Show Submitted Answer Hide Correct Answer Check My Answer

Linear Congruential Generator


Review

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)?

Multiple answers: Multiple answers are accepted for this question

Select one or more answers and submit. For keyboard navigation... SHOW MORE

a the greatest common divisor of a and m is 1

b a-1 is divisible by 4 if m is divisible by 4


c a-1 is divisible by all prime factors of m

d None of the above

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

Show Submitted Answer Hide Correct Answer Check My Answer

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)

Show Submitted Answer Hide Correct Answer Check My Answer


Linear Congruential Generator: Example 1
Review

What is the period-length of the Linear Congruential Generator with seed ?

Type your numeric answer and submit

Correct Answer:
1.0

Show Submitted Answer Hide Correct Answer Check My Answer

Treap: Time and Space Compelxity


Review

Which are true of the time and space complexity of a Treap (Randomized BST)?

Multiple answers: Multiple answers are accepted for this question

Select one or more answers and submit. For keyboard navigation... SHOW MORE

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)

d Its average case space 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 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)

Show Submitted Answer Hide Correct Answer Check My Answer

Linear Congruential Generator: Example 2


Review

What is the period-length of the Linear Congruential Generator with seed ?

Type your numeric answer and submit

Correct Answer:
12.0

Show Submitted Answer Hide Correct Answer Check My Answer

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

a The word Treap is a hybrid of Tree and Heap

b Each node in a Treap has a KEY used for searching

c Each node in Treap has a PRIORITY which represents the number of descendant nodes

d A Max-Heap property is also followed in a Treap based on the KEY

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

Show Submitted Answer Hide Correct Answer Check My Answer

Linear Congruential Generator: Example 2


Review

What is the period-length of the Linear Congruential Generator with seed ?

Type your numeric answer and submit

Correct Answer:
13.0
Show Submitted Answer Hide Correct Answer Check My Answer

Birthday Paradox: Take 2


Review

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

Show Submitted Answer Hide Correct Answer Check My Answer


Multiplicative Congruential Generator
Review
A Multiplicative Congruential Generator is like a Linear Congruential Modifier except that the increment b = 0, i.e
. Depending on the values of a and m, which periods (cycles before returning to beginning)
are possible?

Multiple answers: Multiple answers are accepted for this question

Select one or more answers and submit. For keyboard navigation... SHOW MORE

a all m numbers 0 thru m-1 (full period)

b all numbers 1 thru m-1

c period of maximum length m/4

d None of the above

Correct Answers:
b - all numbers 1 thru m-1
c - period of maximum length m/4

Show Submitted Answer Hide Correct Answer Check My Answer

Fermat's Little Theorem


Review

Which are true of Fermat's Little Theorem?

Multiple answers: Multiple answers are accepted for this question

Select one or more answers and submit. For keyboard navigation... SHOW MORE

a when p is prime then a^(p-1) = 1 mod p

b when p is prime then a^p = a mod p


c when p is not prime then a^(p-1) != 1 mod p

d when p is not prime then a^p != a mod p

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

Show Submitted Answer Hide Correct Answer Check My Answer

Random Numbers for Rolling a Pair of Dice


Review

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())

e floor(6 rand()) + ceil(6 rand())

f floor(6 rand()) + floor(6 rand())

g ceil(6 rand()) + ceil(6 rand())

Correct Answer:
g - ceil(6 rand()) + ceil(6 rand())

Show Submitted Answer Hide Correct Answer Check My Answer

Random Numbers for Estimating Pi


Review

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

Show Submitted Answer Hide Correct Answer Check My Answer

Traditional Binary Search


Review

Which are true of the traditional Binary Search algorithm?

Multiple answers: Multiple answers are accepted for this question

Select one or more answers and submit. For keyboard navigation... SHOW MORE
a It uses a Variable-Size Decrease-and-Conquer design technique

b Its average case time complexity is Θ(log n)

c Its worst case time complexity is Θ(n)

d It can be implemented iteratively or recursively

e None of the above

Correct Answers:
b - Its average case time complexity is Θ(log n)
d - It can be implemented iteratively or recursively

Show Submitted Answer Hide Correct Answer Check My Answer

Randomized Binary Search


Review

Which are true of the randomized Binary Search algorithm?

Multiple answers: Multiple answers are accepted for this question

Select one or more answers and submit. For keyboard navigation... SHOW MORE

a It uses a Variable-Size Decrease-and-Conquer design technique

b Its average case time complexity is Θ(log n)

c Its worst case time complexity is Θ(n)

d It can be implemented iteratively or recursively

e None of the above


Correct Answers:
a - It uses a Variable-Size Decrease-and-Conquer design technique
b - Its average case time complexity is Θ(log n)
c - Its worst case time complexity is Θ(n)
d - It can be implemented iteratively or recursively

Show Submitted Answer Hide Correct Answer Check My Answer

Randomized Binary Search: Example


Review

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

Show Submitted Answer Hide Correct Answer Check My Answer

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.

a x^2 + y^2 > 1

b x^2 + y^2 < 1

c (x-1)^2 + (y-1)^2 > 1

d (x-1)^2 + (y-1)^2 < 1

e x^2 + y^2 > 2

f x^2 + y^2 < 2

g (x-1)^2 + (y-1)^2 > 2

h (x-1)^2 + (y-1)^2 < 2


Correct Answer:
b - x^2 + y^2 < 1

Show Submitted Answer Hide Correct Answer Check My Answer

Estimation of Pi Using Random Numbers


Review

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

Show Submitted Answer Hide Correct Answer Check My Answer

Enter your text here...

Exported for YONGYING MAI on Sat, 27 Aug 2022 02:05:18 GMT

You might also like