12.07.2015 Views

seminar of probability and random processes applied in computer

seminar of probability and random processes applied in computer

seminar of probability and random processes applied in computer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮SEMINAR OF PROBABILITYAND RANDOM PROCESSESAPPLIED IN COMPUTERSCIENCE AND ENGINEERING◭◮Page 1 <strong>of</strong> 25II. SOME EXAMPLES: R<strong>and</strong>om graphs,The Quicksort <strong>and</strong> F<strong>in</strong>d algorithmsPLINIO TRIANA BUSTOSGo BackFull ScreenCloseQuitBook: Probability Models for Computer Science,Sheldon M. Ross. Academic Press, 2002.


1. Some Examples1.1. A R<strong>and</strong>om GraphSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle PageA graph consists <strong>of</strong> a set <strong>of</strong> elements V called vertices <strong>and</strong>a set A <strong>of</strong> vertices called edges (or arcs). It is usual to representsuch a system graphically by draw<strong>in</strong>g circles for vertices<strong>and</strong> draw<strong>in</strong>g l<strong>in</strong>es between vertices i <strong>and</strong> j when (i, j)is an edge. For <strong>in</strong>stance, V = {1, 2, 3, 4, 5, 6} <strong>and</strong> A ={(1, 2), (1, 4), (1, 5), (2, 3), (2, 5), (3, 5), (5, 6)}◭◭◭◮◮◮A sequence <strong>of</strong> vertices i, i 1 , i 2 , ..., i k , j, for which(i, i 1 ), (i 1 , i 2 ), ..., (i k−1 , i k ), (i k , j) are distic edges, is calleda path form vertex i, to vertex 6.Page 2 <strong>of</strong> 25Go BackA graph is said to be connected if there a path beween each pair<strong>of</strong> vertices.Full ScreenCloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageConsider now the graph with vertex set V = {1, 2, ..., n} <strong>and</strong>edge set A = {(i, X(i)), i = 1, ..., n}, where X(i) are <strong>in</strong>dependentr<strong>and</strong>om variables such that◭◭Title Page◮◮P {X(i) = j} = P j ,n∑P j = 1j=1◭ ◮Page 3 <strong>of</strong> 25Go BackFull ScreenIn other words, from each vertex we r<strong>and</strong>omly choose, accord<strong>in</strong>gto the probabilities P j , j = 1, . . . , n another vertex <strong>and</strong> thenjo<strong>in</strong> these two vertices by an edge. We call (i, X(i)) the edgeemanat<strong>in</strong>g from vertex i.A graph <strong>of</strong> te type be<strong>in</strong>g condidered is commonly called a r<strong>and</strong>omgraph . We are <strong>in</strong>terested <strong>in</strong> determ<strong>in</strong><strong>in</strong>g the <strong>probability</strong> thatthis r<strong>and</strong>om graph is connected.CloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Choose some vertex, say perhaps vertex 1, <strong>and</strong> followthe sequence <strong>of</strong> vertices 1, X(1), X 2 (1), . . .,where X n =X(X n−1 (1)), y def<strong>in</strong>e N to equal the first k for wich X k (1)is not a new vertex. That is,Home PageTitle PageN = m<strong>in</strong>(k : X k (1) ∈ {1, X(1), X 2 (1), . . . X k−1 (1))In addition, let◭◭◭◮◮◮W = P 1 +∑N−1i=1P X i (1) = 1Page 4 <strong>of</strong> 25Go BackFull ScreenCloseQuitN, is the number <strong>of</strong> vertices reached <strong>in</strong> the sequence1, X(1), X 2 (1), . . . before a vertex appears twice, <strong>and</strong> W is thesum <strong>of</strong> the probabilites <strong>of</strong> these vertices.


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTo obta<strong>in</strong> the <strong>probability</strong> that the graph is connected,we condition on N <strong>and</strong> the sequence <strong>of</strong> vertices1, X(1), X 2 (1), . . . X N−1 (1). Now, given these values, theN vertices {1, X(1), X 2 (1), . . . X N−1 (1), are connected toeach other, there are one <strong>of</strong> the other n − N vertices will go <strong>in</strong>toone <strong>of</strong> these vertices with <strong>probability</strong> W .◭◭Title Page◮◮Lemma 1 Consider a r<strong>and</strong>om graph consist<strong>in</strong>g <strong>of</strong> vertices0, 1, . . . , r <strong>and</strong> edges (i, Y i ), i = 1, . . . , r,where the Y i are <strong>in</strong>dependent<strong>and</strong> such that◭◮Page 5 <strong>of</strong> 25P {X(i) = j} = Q j , j = 0, . . . , r,r∑Q j = 1j=0Go BackFull ScreenCloseIn other words, this r<strong>and</strong>om graph consists <strong>of</strong> r ord<strong>in</strong>ary vertices<strong>and</strong> one special vertex; out <strong>of</strong> each ord<strong>in</strong>ary vertex there is anedge that <strong>in</strong>dependetly goes <strong>in</strong>to vertex j with <strong>probability</strong> Q j ;there is no edge emanat<strong>in</strong>g form the special vertex. Then,QuitP {graph is connected} = Q 0


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 6 <strong>of</strong> 25Go BackFull ScreenClosePro<strong>of</strong>. By <strong>in</strong>duction on r. As it is clearly true when r = 1,assume it to be true for all values less than r. Now, considerY i , <strong>and</strong> note the follow<strong>in</strong>g. If Y i , then, because the additionalr-1 edges are not enough to connect the graph <strong>of</strong> r + 1 separatevertices, the graph will not be connected. If y 1 = 0, then vertices1 <strong>and</strong> 0 can be rearded as a s<strong>in</strong>gle vertex <strong>and</strong> the situation isthe same as if we had r − 1 ord<strong>in</strong>ary vertices <strong>and</strong> one specialvertex, wigh each ord<strong>in</strong>ary vertex hav<strong>in</strong>g an edge that goes <strong>in</strong>tothe special vertex with <strong>probability</strong> Q 0 + Q 1 . If Y 1 = j ≠ 0, 1,then by regard<strong>in</strong>g vertices 1 <strong>and</strong> j as a s<strong>in</strong>gle vertex, the situationis the same as if we had r − 1 ord<strong>in</strong>ary vertices <strong>and</strong> one specialvertex, with each ord<strong>in</strong>ary vertex hav<strong>in</strong>g an edge that goes <strong>in</strong>tothe special vertex with <strong>probability</strong> Q 0 . Hence, form the <strong>in</strong>ductionhypotheisi, we see that0 ifj = 1P{graph is connected|Y 1 = j} = Q 0 + Q 1 if j = 0Q 0 if j ≠ 0, 1Quit


Therefore, condition<strong>in</strong>g on Y 1 yieldsSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 7 <strong>of</strong> 25Go BackFull ScreenCloseP {graph is connected} =r∑P {graph is connected|Y 1 = j}Q jj=0= (Q 0 + Q 1 )Q 0 + Q 0 (1 − Q 0 − Q 1 )= Q 0 □Return<strong>in</strong>g to the orig<strong>in</strong>al r<strong>and</strong>om graph, it follows, upon regard<strong>in</strong>gthe set <strong>of</strong> vertcices 1, X(1), X 2 (1), . . . , X N−1 (1) as the specialvertex Lemma 1, thatP {graph is connected|N, 1, . . . , X N−1 (1)} = WFor the rest, we will restrict attention to the special case wherethe edge emanat<strong>in</strong>g from each vertex is equally likely to go toany <strong>of</strong> the n vertices <strong>of</strong> the graph.P j = 1/n, j = 1, . . . , nQuit


Proposition 1 P {graph is connected} = E [W ]Corollary 1 When P j = 1/nSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageP {graph is connected} =Pro<strong>of</strong> Because W = N/n, we have(n − 1)!n n∑n−1j=0n jj!Title Page◭◭ ◮◮◭ ◮Page 8 <strong>of</strong> 25Go BackFull ScreenCloseQuitE[W ] = 1 n E [W ]n−1= 1 ∑P {N > i}n= 1 n= 1 n==i=0n−1∑i=0n−1∑i=0(n − 1)!n n(n − 1)!n n(n − 1) . . . (n − i)n i(n − 1)!(n − i − 1)!n <strong>in</strong>−1∑i=0n−1∑i=0n n−1−i(n − i − 1)!n jj! □


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 9 <strong>of</strong> 25Go BackTo obta<strong>in</strong> a simple approximation for the <strong>probability</strong> that thegraph is connected when n is large, note that if X is a Poissonr<strong>and</strong>om variable with mean n then∑n−1P {X < n} = e −nHowever, bacause a Poisson a r<strong>and</strong>om variable with mean n canbe regarded as be<strong>in</strong>g the sum <strong>of</strong> n <strong>in</strong>dependent Poisson r<strong>and</strong>omvariables with mean 1, it follows from teh C.L.T. that such a rondomvariable is less than its mean with <strong>probability</strong> 1/2, this impliesthati=0n ii!Full ScreenP {X < n} ∼ 1 2CloseQuit


Consequently, for n largeSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home Page∑n−1i=0n ii! ∼ en2Hence, from Corollary 1, we se that for large n,Title Page◭◭ ◮◮◭ ◮Page 10 <strong>of</strong> 25Go BackFull ScreenCloseQuit(n − 1)!enP graph is conected ∼ = n!en2n n 2n n+1Therefore, upon us<strong>in</strong>g Stirl<strong>in</strong>g’s approximation, which states thatn! ∼ n n+1/2 e −n√ 2πwe see that, for n large√2πP graph is conected ∼2 √ 2nTherefore, we have shown the folow<strong>in</strong>g.Theorem 1 For n large, P{graph is connected} ∼ √ π2n


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮A graph is said to consist <strong>of</strong> r components if its vertices can bepartitioned <strong>in</strong>to r subsets so that each subest is connected <strong>and</strong>, <strong>in</strong>addition, there are no edges between vertices <strong>in</strong> differents subsets.◭◮Page 11 <strong>of</strong> 25Go BackFull ScreenCloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageLet C denote the number <strong>of</strong> components <strong>in</strong> the r<strong>and</strong>om graphbe<strong>in</strong>g considered, <strong>and</strong> let us compute its expected value. To doso, we will first argue that every component must conta<strong>in</strong> exactlyone cycle, where a cycle is an edge <strong>of</strong> the form (i, i), or sequence<strong>of</strong> edges <strong>of</strong> the form (i, i 1 ), (i 1 , i 2 ), . . . , (i k , i) for dist<strong>in</strong>c verticesi, i 1 , . . . , i k .Title Page◭◭◮◮◭◮Page 12 <strong>of</strong> 25Go BackFull ScreenCloseQuitNote that connected graph consist<strong>in</strong>g <strong>of</strong> the same number <strong>of</strong>edges as vertices must conta<strong>in</strong> exactly one cycle. Hence because<strong>in</strong> the r<strong>and</strong>om graph there is exactly one edge emanat<strong>in</strong>g fromeach vertex, it follows that a component consist<strong>in</strong>g <strong>of</strong> k verticesmust have exactly k edges <strong>and</strong> thus one cycle.


For S ⊂ {1, . . . , n}, say that S is a cycle if there exists a cyclewhose vertices are the vertices <strong>of</strong> S, Consequently, if we letSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮then1,if S is a cycleI(S) = { 0, otherwiseE[C] = E[number <strong>of</strong> cycles]= E[ ∑ SI(S)] = ∑ SE[I(S)]◭◮Page 13 <strong>of</strong> 25Go BackFull ScreenCloseQuitIf S consists <strong>of</strong> a s<strong>in</strong>gle vertex, say S = {1}, then S will be acycle if X(1) = 1, thus E(I({1}) = P {X(1) = 1} = 1 nIf S consists <strong>of</strong> <strong>of</strong> k > 1 vertices, say S = {1, . . . , k}, then Sconstitute a cycle if 1, X(1), . . . , X k−1 are all dist<strong>in</strong>c values <strong>in</strong>S, <strong>and</strong> X k = 1. Therefore,E[I(S)] = k − 1 k − 2n n. . . 1 1n n


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 14 <strong>of</strong> 25( nk )Consequently, as there are subsets <strong>of</strong> size k, we see thatn∑ ( nk ) (k − 1)!E[C] =k=1n kGo BackFull ScreenCloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 15 <strong>of</strong> 25Go BackFull Screen2. The Quicksort <strong>and</strong> F<strong>in</strong>d AlgorithmsSuppose that we want to sort a given set <strong>of</strong> n dist<strong>in</strong>c values,x 1 , x 2 , . . . , x n . A more efficient algorithm than bubble sort fordo<strong>in</strong>g so is the quicsort algorithm, which is recursively def<strong>in</strong>edas follows. When n = 2, the algorithm compares the two valuesan puts them <strong>in</strong> the appropriate order. Whem n > 2, one <strong>of</strong> thevalues is chosen, say it is x i , <strong>and</strong> then all <strong>of</strong> the other values arecompared with x i . Those smaller than x i , are put <strong>in</strong> bracket to theleft <strong>of</strong> x i , <strong>and</strong> those larger than x i ,are put <strong>in</strong> a bracket to the right<strong>of</strong> x i . The algorithm the repeats itself <strong>in</strong> these brackets, cont<strong>in</strong>u<strong>in</strong>guntil all values have been sorted. For <strong>in</strong>stance, suppose thatwe desire to sort the follow<strong>in</strong>g 10 dist<strong>in</strong>ct values:CloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 16 <strong>of</strong> 25Go BackFull Screen5, 9, 3, 10, 11, 14, 8, 4, 17, 6{5, 9, 3, 8, 4, 6,} 10, {11, 14, 17,}{5, 3, 4}, 6, {9, 8,} 10, {11, 14, 17,}{3}, 4, {5}, 6, {9, 8,} 10, {11, 14, 17,}It is <strong>in</strong>tuitively that the worst case occurs when every comparisonvalue chosen is an extreme value. In this worst scenario, thenumber <strong>of</strong> comparisons need is (n − 1) + (n − 2) + . . . + 1 =n(n − 1)/2.A better <strong>in</strong>dication by determ<strong>in</strong>ig the average number <strong>of</strong> comparisonsneeded when the compararison value are r<strong>and</strong>omly chosen.CloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Let X denote the number <strong>of</strong> comparisons needed . Let 1 denotethe smallest value, let 2 denote the second value smallest, <strong>and</strong> soon. Then, for 1≤ i < j ≤ n, let I(i, j) equal 1 if i <strong>and</strong> j areever directly compared, <strong>and</strong> let it equal 0 otherwise.Home PageTitle PageX =n∑j=2j−1∑i=1I(i, j)◭◭◮◮which implies that◭ ◮Page 17 <strong>of</strong> 25Go BackFull ScreenCloseQuitE[X] = E[==n∑j=2j−1∑i=1I(i, j)]j−1 n∑ ∑E[I(i, j)]j=2i=1j−1 n∑ ∑P {i <strong>and</strong> j are ever compared}j=2i=1


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 18 <strong>of</strong> 25Go BackTo determ<strong>in</strong>e the <strong>probability</strong> that i <strong>and</strong> j are ever compared, notethat the values i, i + 1, . . . , j − 1, j will <strong>in</strong>itially be <strong>in</strong> the samebracket <strong>and</strong> will rema<strong>in</strong> <strong>in</strong> the same bracket if the number chosenfor the first comparison is not between i <strong>and</strong> j. Thus, the<strong>probability</strong> that it is i or j is 2/(j − i + 1). Therefore,P {i <strong>and</strong> j are ever compared} =2j − i + 1Full ScreenCloseQuit


Consequently, we see thatSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 19 <strong>of</strong> 25E[X] == 2= 2= 2n∑ ∑j−1j=2 i=1n∑j=2 k=2n∑2n∑j − 1 + 1 = 2 ( 1 j + 1j − 1 . . . 1 3 + 1 2 )j∑k=2 j=kn∑k=2n∑= 2(n + 1)1k1kn − k + 1kn∑k=2=n∑k=2j=21− 2(n − 1)k2(n + 1)k−n∑k=22kkGo BackFull ScreenCloseFor large nn∑k=21k ∼ log(n)Thus, the quicsort algorithm requieres, on average, approximately 2n log(n)comparison to sort n values.Quit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 20 <strong>of</strong> 25Go BackFull Screen2.1. The F<strong>in</strong>d AlgorithmSuppose that we want to f<strong>in</strong>d the kthsmallest <strong>of</strong> a list. The f<strong>in</strong>dalgorithm is quite similar to quicksort; Suppose that r − 1 itemsare put <strong>in</strong> the bracket to left. There are now three possibilities:{2, 5, 4, 3}, 6, { 10, 21, 16, 18}1. r = k then, the algorithm ends.2. r < k then, kth smallest value is the (k − r)th smallest <strong>of</strong>the n − r values <strong>in</strong> the right bracket3. r > k then, search for the kth smallest <strong>of</strong> the r − 1 values <strong>in</strong>the left bracket.CloseQuit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 21 <strong>of</strong> 25Go BackFull ScreenCloseWe have, as <strong>in</strong> the quicksort analysis,<strong>and</strong>E[X] =X =n∑ ∑j−1I(i, j)j=2 i=1n∑ ∑j−1P {i <strong>and</strong> j are ever compared}j=2 i=1To determ<strong>in</strong>e the <strong>probability</strong> that i <strong>and</strong> j are ever compared, weconsider cases:Case 1 i < j ≤ kIn this case i, j, k will rema<strong>in</strong> together until one <strong>of</strong> the valuesi, i + 1, . . . , k is chosen as the comparison value.P {i <strong>and</strong> j are ever compared} =2k − i + 1Quit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 22 <strong>of</strong> 25Go BackCase 2: i ≤ k < jCase 3: k < i < jP {i <strong>and</strong> j are ever compared} =P {i <strong>and</strong> j are ever compared} =2j − i + 12j − k + 1Full ScreenCloseQuit


It follow from the preced<strong>in</strong>g thatSome ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .1n∑2 E[X] =j−1∑j=2 i=11k − i + 1 +n∑k∑j=k+1 i=11j − i + 1 +n∑j−1∑j=k+2 i=k+11j − i + 1Home PageTitle Page◭◭ ◮◮◭ ◮Page 23 <strong>of</strong> 25Go BackFull ScreenCloseTo the approximate the preced<strong>in</strong>g when n <strong>and</strong> k are large, letk = αn for 0 < α < 1. Now,n∑j=2j−1∑i=1k−11k − i + 1 = ∑==k∑i=1 j=i+1∑k−1i=1k∑j=2k − ik − i + 1j − 1j∼ k − log(k)∼ k = αn1k − i + 1Quit


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 24 <strong>of</strong> 25Go BackFull ScreenCloseQuitn∑k∑j=k+1 i=11n∑j − i + 1 =∼∼∼∼As it similarly follows thatwe see thatn∑j−1∑j=k+2 i=k+1j=k+1n∑j=k+1∫ nk1j − k + 1(1j − k + 1 + . . . , 1 )j(log(j) − log(j − k))log(x)dx −∫ n−k1log(x)dxn log(n) − n − (αn log(αn) − αn)−(n − αn) log(n − αn) + (n − αn)n[−α log(α) − (1 − α) log(1 − α)]= n − k = n(1 − α)E[X] ∼ 2n[1 − α log(α) − (1 − α) log(1 − α)]□Thus, the mean number <strong>of</strong> comparison needed by the f<strong>in</strong>d algorithmis a l<strong>in</strong>ear function <strong>of</strong> ghe number <strong>of</strong> values.□


Some ExamplesThe Quicksort <strong>and</strong> F<strong>in</strong>d . . .Home PageTitle Page◭◭ ◮◮◭ ◮Page 25 <strong>of</strong> 25Go BackFull ScreenReferences[1] G.R. Grimmett <strong>and</strong> D.R. Stirzaker. Probability <strong>and</strong> R<strong>and</strong>omProcess. Oxford Science Publications, 1998.[2] C.M. Gr<strong>in</strong>stead <strong>and</strong> J.L. Snell. Introduction to Probability.American Mathematical Society, 1997.[3] H.P. Hsu. Probability, R<strong>and</strong>om Variables, <strong>and</strong> R<strong>and</strong>om Processes.McGraw Hill- Schaum, 1996.[4] F.P. Kelly. Probability. Notes form The Archimedeanshttp://www.cam.ac.uk/societies/archim/notes.html, 1996.CloseQuit

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!