CS 600 Solutions to Homework 2



1 (a) Note that $2^{j-1}$ keys are found with $j$ comparisons. So 31 keys are found each with 5 or less comparisons. Hence $p(i) = 0.4$/$31$ for the $i$-th key if it is found with at most 5 comparisons i.e. if $i$ = $j(n+1)$/$32$, where $1 \leq j \leq 32$.

There are $2^{k} - 32$ other keys and they together occur $60$% of the time. Hence $p(i) = 0.6$/$(n-31)$ if the $i$-th key is found with 6 or more comparisons.


(b) The average number of comparisons is equal to

$(0.4$/$31)$ $( 1*1 + 2*2 + 3*2^{2} + 4*2^{3} + 5*2^{4} )$ $+$ ( $0.6$/$(n-31)$ ) $(6*2^{5} + ... + i*2^{i-1} + ... + k*2^{k-1})$ = $(0.4$/$31)$ $\Sigma_{i=1}^{5} i*2^{i-1} + $( $0.6$/$(n-1)$ ) $\Sigma_{i=1}^{k} i*2^{i-1} $ $- \Sigma_{i=1}^{5} i*2^{i-1} $

Using the formula $\Sigma_{i=1}^{n}i*2^{i-1} = (n-1)*2^{n} + 1$, this becomes equal to

$0.4*129$/$31$ + ( $0.6$/$(n-31)$ )( $(lg(n+1) - 1)(n+1) - 128$ ) .

2. For example an adjacency list for a graph with 4 vertices can be represented by the string (1:2,3,4; 2:3,4; 3:2,4; 4:1,3). Then this string can be coded with ASCII code for example. (For your answer you need to present this argument in general way.)

3. Since the polynomial is known, compute the polynomial for the string in question and run the algorithm that accepts it in that much time. If it accepts then it is in L, else it is not in L.

4. Choose as a certificate a mapping of the vertices of G1 to those of G2. Let us denote this mapping by f.
We need to check the following:
(a) Every vertex of G1 is mapped to a vertex of G2.
(b) f(u) is not equal to f(v) if u is not equal to v.
(c) (u, v) is an edge of G1 if and only if ( f(u), f(v) ) is an edge of G2.

Let n be the number of vertices in G1. Then (a) takes O(n lg n) time (O(n) if hashing can be used), (b) also can be done in O(n lg n) and O(n2 lg n) is sufficient for (c), since the number of edges is at most O(n).