CS5050 Homework 5 Chapter 10 and test review
CS5050 Homework 5 Chapter 10 and test review
CS5050 Homework 5 Chapter 10 and test review
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>CS5050</strong> <strong>Homework</strong> 5<br />
<strong>Chapter</strong> <strong>10</strong> <strong>and</strong> <strong>test</strong> <strong>review</strong><br />
1. Consider a Monte Carlo algorithm A for a problem P whose expected running time is at most T (n) on<br />
any instance of size n <strong>and</strong> that produces a correct solution with probability fl(n). Suppose further that<br />
given a solution to P , we can verify its correctness in time t(n). Show how to obtain a Las Vegas<br />
Algorithm that always gives a correct answer to P <strong>and</strong> runs in expected time at most (T(n) + t(n))/fl(n).<br />
2. Liz conjectures that for any n, n-1 is its own inverse mod n. Prove or disprove this conjecture.<br />
3. Discuss the relationship between the FastExponentiation (page 463) for n k <strong>and</strong> the binary representation<br />
for k.<br />
4. Show the execution of ExtendedEuclidGCD(412,113) by constructing a table similar to Table <strong>10</strong>.<strong>10</strong><br />
(page 465).<br />
5. Prove Corollary <strong>10</strong>.7: if gcd(x,n) = 1 then Zn={ix mod n:i=0,1,...,n-1}<br />
6. (C-<strong>10</strong>.4) Show how to modify algorithm ExtendedEuclidGCD to compute the multiplicative inverse of<br />
an element in Zn using arithmetic operations on oper<strong>and</strong>s with at most 2log n bits.<br />
7. Compute successive powers for the elements of Z17 in a table similar to that of Table <strong>10</strong>.5 (page 460).<br />
8. Compute the multiplicative inverses of 113, 114, <strong>and</strong> 127 in Z299.<br />
9. Construct the modulo multiplication table for Z11<br />
* 0 1 2 3 4 5 6 7 8 9 <strong>10</strong><br />
0<br />
1<br />
2<br />
3 7<br />
4<br />
5 9<br />
6<br />
7<br />
8<br />
9<br />
<strong>10</strong><br />
<strong>10</strong>. Consider the following algorithm for GCD:<br />
int binGCD(int a,int b)<br />
{ if (a == 0) return b;<br />
if (b == 0) return a;<br />
if (a%2==0 && b % 2 = 0) return 2*binGCD(a/2,b/2);<br />
if (a%2==1 && b % 2 = 0) return binGCD(a,b/2);<br />
if (a%2==0 && b % 2 = 1) return binGCD(a/2,b);<br />
return binGCD(Math.abs(a-b)/2, b);<br />
}<br />
A friend says, ``I don't like it. When I call binGCD(3,15), it creates a call<br />
to binGCD(6,15). This makes me nervous because we have turned a smaller<br />
problem into a larger problem. I was taught recursion shouldn't do that?''<br />
How do you answer your friend?
11. For any integers a <strong>and</strong> b, if d|a <strong>and</strong> d|b then d|gcd(a,b) . Prove this.<br />
12. If p if a prime, the inverse of x mod p is given by:<br />
(a)<br />
(b)<br />
(c)<br />
(d) there may not be an inverse for x<br />
13. For n = 12, what is Φ(n)?<br />
(a) 2 (b) 3 (c) 4 (d) 6 (e) 12<br />
14. For n = 17*23, what is Φ(n) ?<br />
(a) 17 (b) 45 (c) 40 (d) 352 (e) 390<br />
15. Which is true of the Boyer-Moore Algorithm for matching pattern P in text T?<br />
a. the algorithm begins searching at the end of the pattern string<br />
b. if the mismatch occurs at T[i] = c <strong>and</strong> c occurs nowhere in P, the entire pattern is shifted<br />
past T[i].<br />
c. if the mismatch occurs <strong>and</strong> T[i] = c <strong>and</strong> c occurs at location L[c], you only move one<br />
location, if moving to L[c] would shift the pattern backwards.<br />
d. all of the above<br />
e. none of the above<br />
16. In constructing the last function for the Boyer-Moore Algorithm in which the pattern length is<br />
m <strong>and</strong> the total alphabet is A, the complexity would be<br />
a. O(A)<br />
b. O(m+A)<br />
c. O(mA)<br />
d. O(1)<br />
17. In a st<strong>and</strong>ard trie containing n strings, the height of the trie is<br />
a. log n<br />
b. the length of the longest string<br />
c. slightly more than the height of the average string<br />
d. no formula for height is known, as it depends on the specific data<br />
e. none of the above<br />
18. The binary failure table (assuming a binary input string) for the string ddedddeeded as<br />
follows:
a.<br />
b.<br />
c.<br />
d.<br />
e. None of the above<br />
19. We want to find two numbers - one which is smaller than the median <strong>and</strong> one which is larger<br />
than the median. We pick three numbers. We claim the biggest is above the median <strong>and</strong> the<br />
smallest is below the median. What is the probability we have made an error?<br />
(a) .05 (b) .125 (c) .25 (d) .50 (e) 1<br />
20. Given any number x, the easiest way to find its inverse mod n is<br />
a. build a table of powers of x <strong>and</strong> stop when you get to a 1.<br />
b. build a multiplication table for Zn <strong>and</strong> look for a 1 in the x column or row.<br />
c. use extendedGCD(x,n) <strong>and</strong> use xmult as the possible inverse.<br />
d. if gcd(x,n) = 1, the inverse is 1/x.<br />
e. none of the above