Quadratc speedup for unstructured search - Grover s Al- CS 94- gorthm /8/07 Sprng 007 Lecture 11 001 Unstructured Search Here s the problem: You are gven a boolean functon f : {1,,} {0,1}, and are promsed that for eactly one a {1,, }, f(a) = 1 Thn of ths as a table of sze, where eactly one element has value 1, and all the others are 0 Snce we assume f can be computed classcally n polynomal tme, we can also compute t n superposton: α 0 α f() As we saw before, we can use crcut for f to put nformaton about f() n the phase by effectng the transformaton: α α ( 1) f() Here s another way of creatng ths phase state: ( α 0 1 ) ( f() f() ) α ( ) = α f() f() = α ( 1) f() ( 0 1 ) ow, we mght as well assume f s a blac bo or oracle All we need to do s desgn an algorthm that fnds a : f(a) = 1 00 Grover s algorthm Grover s algorthm fnds a n O( ) steps Consder the dmensonal Hlbert space spanned by 1,, We wsh to fnd a There s a state that we can create: = 1 Consder the two dmensonal subspace spanned by a and Let e be the state orthogonal to a n ths subspace Let θ be the angle between and e Then sn θ = 1/ and therefore θ 1/ See Fgure?? for an llustraton of these vectors a s the target, so we want to ncrease θ But how? One way to rotate a vector s to mae two reflectons In partcular, we can rotate a vector v by θ by reflectng about e and then reflectng about Ths transformaton s also llustrated n Fgure?? Each step of our algorthm s a rotaton by θ (we dscuss the mplementaton below) Ths means that we need π/ θ teratons for the algorthm to complete ow, what s θ? CS 94-, Sprng 007, Lecture 11 0-1
(apts) (v pts) (v pts) θ φ θ θ + φ (ψ 0 pts) = 1 =1 ( pts) (e pts) Fgure 01: To rotate v by θ to v, we reflect around e and then reflect around ψ 0 ψ 0 a = cos(π/ θ) = sn(θ) = 1 Snce sn θ θ, we now that θ 1 Thus, we need O( ) teratons for the algorthm to complete In the end, we get very close to a, and then wth hgh probablty, a measurement of the state yelds a How do you mplement the two reflectons? 1 Reflecton about e s easy We can reflect about the hyperplane orthogonal to a by flppng the phase of the component n the drecton of a ; e carry out the transformaton α α ( 1) f() For the reflecton about u, we wll actually reflect about n the dmensonal space as follows: apply the Hadamard transform H n to transform to 0 n ow apply a phase flp f the regster contents are anythng other than 0 n And apply the Hadamard transform to swtch bac from the Hadamard bass 003 Another approach Let s loo at the search algorthm dfferently, wth all superpostons The rotaton about u, D, s an nverson about the mean : (a) For = n, D can be decomposed and rewrtten as: CS 94-, Sprng 007, Lecture 11 0-
1 0 0 0 1 0 D = H H 0 0 1 0 0 = H + I H 0 0 = H H + I / / / / / / = + I / / / / + 1 / / / / + 1 / = / / / + 1 Observe that D s epressed as the product of three untary matrces (two Hadamard matrces separated by a condtonal phase shft matr) Therefore, D s also untary Regardng the mplementaton, both the Hadamard and the condtonal phase shft transforms can be effcently realzed wthn O(n) gates (b) Consder D operatng on a vector α to generate another vector β : D α 1 α = If we let be the mean ampltude, then the epresson descrbes a reflecton of about the mean Thus, the ampltude of β = j α j + = + can be consdered an nverson about the mean wth respect to The quantum search algorthm teratvely mproves the probablty of measurng a soluton Here s how: (a) Start state s ψ 0 = 1 (b) Invert the phase of a usng f (c) Then nvert about the mean usng D (d) Repeat steps and 3 O( ) tmes, so n each teraton α a ncreases by β 1 β β CS 94-, Sprng 007, Lecture 11 0-3
(a) (b) (c) Fgure 0: The frst three steps of Grover s algorthm We start wth a unform superposton of all bass vectors n (a) In (b), we have used the functon f to nvert the phase of α After runnng the dffuson operator D, we amplfy α whle decreasng all other ampltudes CS 94-, Sprng 007, Lecture 11 0-4
Ths process s llustrated n Fgure?? Suppose we just want to fnd a wth probablty 1 Untl ths pont, the rest of the bass vectors wll have 1 ampltude at least In each teraton of the algorthm, α a ncreases by at least = Eventually, α a = 1 The number of teratons to get to ths α a s 004 More applcatons Grover s algorthm s often called a database search algorthm Ths msnomer has been the cause of a lot of confuson, snce essental that the algorthm be able to query n superposton But there are a number of applcatons of unstructured search: (a) Fnd the mnmum n O( ) steps Eercse (b) Appromately count elements, or generate random ones (c) O( 1/3 ) algorthm for the collson problem (d) Speed up the test for matr multplcaton In ths problem we are gven three matrces, A, B, and C, and are told that the product of the frst two equals the thrd We wsh to verfy that ths s ndeed true An effcent (randomzed) way of dong ths s pcng a random array r, and checng to see whether Cr = ABr = A(Br) Classcally, we can do the chec n O(n ) tme, but usng a smlar approach to Grover s algorthm we can speed t up to O(n 175 ) tme CS 94-, Sprng 007, Lecture 11 0-5