Problems - Mathematical Foundations for Computer Engineering | ENEE 641, Assignments of Electrical and Electronics Engineering

Material Type: Assignment; Professor: JaJa; Class: MATH FNDTN COMPTR ENGR; Subject: Electrical & Computer Engineering; University: University of Maryland; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-i7s-1
koofers-user-i7s-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5

Partial preview of the text

Download Problems - Mathematical Foundations for Computer Engineering | ENEE 641 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Solution to Exercise 5.2-

Since H IRE -ASSISTANT always hires candidate 1, it hires exactly once if and only if no candidates other than candidate 1 are hired. This event occurs when candidate 1 is the best candidate of the n ,

which occurs with probability 1 / n.

HIRE -ASSISTANT hires n times if each candidate is better than all those who were interviewed (and hired) before. This event occurs precisely when the list of ranks given to the algorithm is

< 1 , 2 , … , n >, which occurs with probability 1 / n !.

Solution to Exercise 5.2-

Another way to think of the hat-check problem is that we want to determine the expected number

of fixed points in a random permutation. (A fixed point of a permutation π is a value i for which

π( i ) = i .) One could enumerate all n! permutations, count the total number of fixed points, and

divide by n! to determine the average number of fixed points per permutation. This would be a painstaking process, and the answer would turn out to be 1. We can use indicator random variables, however, to arrive at the same answer much more easily.

Define a random variable X that equals the number of customers that get back their own hat, so

that we want to compute E [ X ]. For i = 1 , 2 , … , n , define the indicator random variable

X i = I {customer i gets back his own hat}. Then X = X 1 + X 2 +· · · + X n. Since the ordering of hats

is random, each customer has a probability of 1 / n of getting back his own hat. In other words, Pr

{ X i = 1 } = 1 / n , which, by Lemma 5.1, implies that E [ X i ] = 1 / n.

Thus,

1

1

1

[ ]

[ ] exp

n i i n i i n i

E X E X

E X linearity of ectation

n

=

=

=

= ⎡^ ⎤

and so we expect that exactly 1 customer gets back his own hat.

Note that this is a situation in which the indicator random variables are not independent. For example, if n = 2 and X 1 = 1, then X 2 must also equal 1. Conversely, if n = 2 and X 1 = 0, then

X 2 must also equal 0. Despite the dependence, Pr { X i = 1 } = 1 / n for all i , and linearity of

expectation holds. Thus, we can use the technique of indicator random variables even in the presence of dependence.

Solution to Exercise 5.2-

Let X i j be an indicator random variable for the event where the pair A [ i ] , A [ j ] for i < j is

inverted, i.e., A [ i ] > A [ j ]. More precisely, we define X i j = I { A [ i ] > A [ j ]} for 1 ≤ i < j ≤ n. We

have Pr{ X i j = 1 } = 1 /2, because given two distinct random numbers, the probability that the first is

bigger than the second is 1 /2. By Lemma 5.1, E [ X i j ] = 1 /2.

Let X be the the random variable denoting the total number of inverted pairs in the array, so that 1 1 1

n n

X i j i Xij

− = = +

= (^) ∑ ∑.

We want the expected number of inverted pairs, so we take the expectation of both sides of the above equation to obtain 1 1 1

[ ]

n n

E X E i j i Xij

− = = +

= ⎡^ ⎤

∑ ∑.

We use linearity of expectation to get 1 1 1 1 1 1 1 1 1

[ ]

[ ]

n n i j i ij n n i j i ij n n i j i

E X E X

E X

n

n n

n n

− = = + − = = + − = = +

= ⎡^ ⎤

= ⎛^ ⎞

∑ ∑

∑ ∑

∑ ∑

Thus the expected number of inverted pairs is n ( n − 1 )/4.

Solution to Exercise 5.3-

P ERMUTE -BY-CYCLIC chooses offset as a random integer in the range 1 ≤ offsetn , and then it

performs a cyclic rotation of the array. That is, B [ (( i + offset − 1 ) mod n ) + 1] ← A [ i ]

for i = 1 , 2 , … , n. (The subtraction and addition of 1 in the index calculation is due to the 1-

origin indexing. If we had used 0-origin indexing instead, the index calculation would have

simplied to B [ ( i + offset ) mod n ]← A [ i ] for i = 0 , 1 , … , n − 1.)