5. DIVIDE AND CONQUER

Size: px
Start display at page:

Download "5. DIVIDE AND CONQUER"

Transcription

1 Divide-ad-coquer paradigm Lecture slides by Kevi Waye Copyright 005 Pearso-Addiso Wesley 5. DIVIDE AND CONQUER I mergesort coutig iversios radomized quicksort media ad selectio closest pair of poits Divide-ad-coquer. Divide up problem ito several subproblems (of the same kid). Solve (coquer) each subproblem recursively. Combie solutios to subproblems ito overall solutio. Most commo usage. Divide problem of size ito two subproblems of size /. Solve (coquer) two subproblems recursively. Combie two solutios ito overall solutio. O() time Cosequece. Brute force: Θ( ). Divide-ad-coquer: O( log ). O() time Last updated o 3/1/18 9:1 AM attributed to Julius Caesar Sortig problem 5. DIVIDE AND CONQUER Problem. Give a list L of elemets from a totally ordered uiverse, rearrage them i ascedig order. mergesort coutig iversios radomized quicksort media ad selectio closest pair of poits SECTIONS

2 Sortig applicatios Mergesort Obvious applicatios. Orgaize a MP3 library. Display Google PageRak results. List RSS ews items i reverse chroological order. Some problems become easier oce elemets are sorted. Idetify statistical outliers. Biary search i a database. Remove duplicates i a mailig list. No-obvious applicatios. Covex hull. Closest pair of poits. Iterval schedulig / iterval partitioig. Schedulig to miimize maximum lateess. Miimum spaig trees (Kruskal s algorithm) Recursively sort left half. Recursively sort right half. Merge two halves to make sorted whole. iput A L G O R I T H M S sort left half A G L O R I T H M S sort right half A G L O R H I M S T merge results A G H I L M O R S T 6 Mergig Mergesort implemetatio Goal. Combie two sorted lists A ad B ito a sorted whole C. Sca A ad B from left to right. Compare a i ad b j. If a i b j, apped a i to C (o larger tha ay remaiig elemet i B). If a i > b j, apped b j to C (smaller tha every remaiig elemet i A). Iput. List L of elemets from a totally ordered uiverse. Output. The elemets i ascedig order. MERGE-SORT(L) IF (list L has oe elemet) RETURN L. sorted list A ai 18 merge to form sorted list C sorted list B 11 bj 0 3 Divide the list ito two halves A ad B. A MERGE-SORT(A). T( / ) B MERGE-SORT(B). T( / ) L MERGE(A, B). Θ() RETURN L. 7 8

3 <latexit sha1_base64="g9biiiqvrcnlak0qbomus1fe8=">aaacy3icbvfdb9mwfhuypkr56syjl1d0ockkljmqmkctekfjzsklkqo8pxbjprjhpzdmojfesp8k/4nzhzjtgo++kjc67p/upkkywnwz+ev3fv/oohvuf9x0+eps+d/4zopkc5zxqhb6mmegpva4s8jkvcw1sjyrejfcfr0i++ojsju1k5ljhovcitflhlqa/pyp1fugpuin06cjlowqufm0mz49deenuisrw4pi4fdbb4goyqouzsngjhscqyjkjnzfbru0tfq3elg9z1zbesoqzaa8ltev98da7t1glxrolwtamwjbglog6mcrdc/vqoafrzkuvkumthzkcxtxdntbzfopqomloxfsyxohvqsrxpx7ti38noxkwrumkxqflr3x81y41z54lzjm9mrtaq/5pm1cm8s1ugvlufgbqlklwrbqxazsozfbuxaacs1cr8cvmgbcuvttvwm9s+rbk9srsglepljdsruymjvbjhz3dhfmjootipr6fg6dbziy/jkziiermtm/kzjmz4v7pc7yxn/g/+nb/4f+8sfw97s8lshx+r7/ftnwb</latexit> <latexit sha1_base64="g9biiiqvrcnlak0qbomus1fe8=">aaacy3icbvfdb9mwfhuypkr56syjl1d0ockkljmqmkctekfjzsklkqo8pxbjprjhpzdmojfesp8k/4nzhzjtgo++kjc67p/upkkywnwz+ev3fv/oohvuf9x0+eps+d/4zopkc5zxqhb6mmegpva4s8jkvcw1sjyrejfcfr0i++ojsju1k5ljhovcitflhlqa/pyp1fugpuin06cjlowqufm0mz49deenuisrw4pi4fdbb4goyqouzsngjhscqyjkjnzfbru0tfq3elg9z1zbesoqzaa8ltev98da7t1glxrolwtamwjbglog6mcrdc/vqoafrzkuvkumthzkcxtxdntbzfopqomloxfsyxohvqsrxpx7ti38noxkwrumkxqflr3x81y41z54lzjm9mrtaq/5pm1cm8s1ugvlufgbqlklwrbqxazsozfbuxaacs1cr8cvmgbcuvttvwm9s+rbk9srsglepljdsruymjvbjhz3dhfmjootipr6fg6dbziy/jkziiermtm/kzjmz4v7pc7yxn/g/+nb/4f+8sfw97s8lshx+r7/ftnwb</latexit> <latexit sha1_base64="g9biiiqvrcnlak0qbomus1fe8=">aaacy3icbvfdb9mwfhuypkr56syjl1d0ockkljmqmkctekfjzsklkqo8pxbjprjhpzdmojfesp8k/4nzhzjtgo++kjc67p/upkkywnwz+ev3fv/oohvuf9x0+eps+d/4zopkc5zxqhb6mmegpva4s8jkvcw1sjyrejfcfr0i++ojsju1k5ljhovcitflhlqa/pyp1fugpuin06cjlowqufm0mz49deenuisrw4pi4fdbb4goyqouzsngjhscqyjkjnzfbru0tfq3elg9z1zbesoqzaa8ltev98da7t1glxrolwtamwjbglog6mcrdc/vqoafrzkuvkumthzkcxtxdntbzfopqomloxfsyxohvqsrxpx7ti38noxkwrumkxqflr3x81y41z54lzjm9mrtaq/5pm1cm8s1ugvlufgbqlklwrbqxazsozfbuxaacs1cr8cvmgbcuvttvwm9s+rbk9srsglepljdsruymjvbjhz3dhfmjootipr6fg6dbziy/jkziiermtm/kzjmz4v7pc7yxn/g/+nb/4f+8sfw97s8lshx+r7/ftnwb</latexit> <latexit sha1_base64="g9biiiqvrcnlak0qbomus1fe8=">aaacy3icbvfdb9mwfhuypkr56syjl1d0ockkljmqmkctekfjzsklkqo8pxbjprjhpzdmojfesp8k/4nzhzjtgo++kjc67p/upkkywnwz+ev3fv/oohvuf9x0+eps+d/4zopkc5zxqhb6mmegpva4s8jkvcw1sjyrejfcfr0i++ojsju1k5ljhovcitflhlqa/pyp1fugpuin06cjlowqufm0mz49deenuisrw4pi4fdbb4goyqouzsngjhscqyjkjnzfbru0tfq3elg9z1zbesoqzaa8ltev98da7t1glxrolwtamwjbglog6mcrdc/vqoafrzkuvkumthzkcxtxdntbzfopqomloxfsyxohvqsrxpx7ti38noxkwrumkxqflr3x81y41z54lzjm9mrtaq/5pm1cm8s1ugvlufgbqlklwrbqxazsozfbuxaacs1cr8cvmgbcuvttvwm9s+rbk9srsglepljdsruymjvbjhz3dhfmjootipr6fg6dbziy/jkziiermtm/kzjmz4v7pc7yxn/g/+nb/4f+8sfw97s8lshx+r7/ftnwb</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="vraymk/lbrqg3uogoqdaffrdfhc=">aaacxxicbvfda9swfjw9ry77srvhvvywbqsmzxyytcnsfpbsxw6strczimvxqagsgukucsbsj+yp7d9mdl1y0twz389y0lmk6kpotha8epr8zo9p79zfy9f9fcpflpdgy4zrqulymzkixcmrno4mvpkbwpxiv0+ujx9ygsukrqvuxmbrsququohoewvr/t4fqcl5cj6a4fkrmvpfd9ogkgvdaha5cdskhq+vz4kpyakxzahsmrejzpkmqc6m1afvpdns0+ajo5aodqcnyflltggqy/xbvdvd917ffxwrbhod6jr1abcb3ehbqsl88v+ceazzascleoswtupo9ilntnoci+rspiyfg1w+lcq8uktedribd57jipf5fo5anl/kpwwlsuup9zmhdld7wg/j8r1x+ktrclzvdxw8h5zuep6h5cwtcihdy7qhjrvhdgv8xw7jz9ua0vyukw9duq8qjbjocievbuuma1ymdz7dbj0zdr/opz4psks3opvcfvyzde5jickjnytmaebewdojghj6fkthzw1qghq1r8lwhl/+aje6018=</latexit> <latexit sha1_base64="vraymk/lbrqg3uogoqdaffrdfhc=">aaacxxicbvfda9swfjw9ry77srvhvvywbqsmzxyytcnsfpbsxw6strczimvxqagsgukucsbsj+yp7d9mdl1y0twz389y0lmk6kpotha8epr8zo9p79zfy9f9fcpflpdgy4zrqulymzkixcmrno4mvpkbwpxiv0+ujx9ygsukrqvuxmbrsququohoewvr/t4fqcl5cj6a4fkrmvpfd9ogkgvdaha5cdskhq+vz4kpyakxzahsmrejzpkmqc6m1afvpdns0+ajo5aodqcnyflltggqy/xbvdvd917ffxwrbhod6jr1abcb3ehbqsl88v+ceazzascleoswtupo9ilntnoci+rspiyfg1w+lcq8uktedribd57jipf5fo5anl/kpwwlsuup9zmhdld7wg/j8r1x+ktrclzvdxw8h5zuep6h5cwtcihdy7qhjrvhdgv8xw7jz9ua0vyukw9duq8qjbjocievbuuma1ymdz7dbj0zdr/opz4psks3opvcfvyzde5jickjnytmaebewdojghj6fkthzw1qghq1r8lwhl/+aje6018=</latexit> <latexit sha1_base64="vraymk/lbrqg3uogoqdaffrdfhc=">aaacxxicbvfda9swfjw9ry77srvhvvywbqsmzxyytcnsfpbsxw6strczimvxqagsgukucsbsj+yp7d9mdl1y0twz389y0lmk6kpotha8epr8zo9p79zfy9f9fcpflpdgy4zrqulymzkixcmrno4mvpkbwpxiv0+ujx9ygsukrqvuxmbrsququohoewvr/t4fqcl5cj6a4fkrmvpfd9ogkgvdaha5cdskhq+vz4kpyakxzahsmrejzpkmqc6m1afvpdns0+ajo5aodqcnyflltggqy/xbvdvd917ffxwrbhod6jr1abcb3ehbqsl88v+ceazzascleoswtupo9ilntnoci+rspiyfg1w+lcq8uktedribd57jipf5fo5anl/kpwwlsuup9zmhdld7wg/j8r1x+ktrclzvdxw8h5zuep6h5cwtcihdy7qhjrvhdgv8xw7jz9ua0vyukw9duq8qjbjocievbuuma1ymdz7dbj0zdr/opz4psks3opvcfvyzde5jickjnytmaebewdojghj6fkthzw1qghq1r8lwhl/+aje6018=</latexit> <latexit sha1_base64="vraymk/lbrqg3uogoqdaffrdfhc=">aaacxxicbvfda9swfjw9ry77srvhvvywbqsmzxyytcnsfpbsxw6strczimvxqagsgukucsbsj+yp7d9mdl1y0twz389y0lmk6kpotha8epr8zo9p79zfy9f9fcpflpdgy4zrqulymzkixcmrno4mvpkbwpxiv0+ujx9ygsukrqvuxmbrsququohoewvr/t4fqcl5cj6a4fkrmvpfd9ogkgvdaha5cdskhq+vz4kpyakxzahsmrejzpkmqc6m1afvpdns0+ajo5aodqcnyflltggqy/xbvdvd917ffxwrbhod6jr1abcb3ehbqsl88v+ceazzascleoswtupo9ilntnoci+rspiyfg1w+lcq8uktedribd57jipf5fo5anl/kpwwlsuup9zmhdld7wg/j8r1x+ktrclzvdxw8h5zuep6h5cwtcihdy7qhjrvhdgv8xw7jz9ua0vyukw9duq8qjbjocievbuuma1ymdz7dbj0zdr/opz4psks3opvcfvyzde5jickjnytmaebewdojghj6fkthzw1qghq1r8lwhl/+aje6018=</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="z3k0jp4wp//6lqi9ep3kfw=">aaaco3icbvfna9taef0pbzq4h3hsyy5dyaufkcyhaseleavpfsqfrsjwmksvinywoldkfbrvap7s0/psthhdrpwc6pnznvzt8mpzkwguc3588ebr5bgu78/zfy1c73d97aojmcrkfrhrhnuuumni5kk8lo0ypne4vvy+6xjx9hsblqq5qxgod8qmumbsdhtbq/hkf6hurcn5csjbqds1cip0yoajieihbgncgmdrqrcw9gave0dvommeuzgdrb3ayx4ng6lt0etd/9dsluass/6facframeazcfvryg5etxw8vsgtr5ahjkg7toaxkimtusaqfbt/kysflz/iehnc7rxvtrpaw8dk0jwghc0wzl9t6pmubxzphgvoacbu55ryp/lxhvlp3etdvkravewkksuuagn45bkg4lu3aeujhs7grjhhgty/7iyzaldolh5strtbrfimusohkz3rgyrvgiwg/u/98pvh3svpa+cwdvbelqm7yf/zjrsxwe69tw/h6/qh/jf/hz98kpw9tuc1wwk//gpfucbd</latexit> <latexit sha1_base64="oidllbbcsvzr990sj0ljhkzac4e=">aaacwxicbvdlsgmxfe3hv6vvpdugkvwucqmccoicg5cvrc0kldjrtozlkso6izehv+dvu9r8ep8b0sbdvc0lozrk3n/feqrqwff+r4ksrq1vfddlw9s7u3vlyv6j1zh0oraatoomqupfdrroiraoalsyrwplyd6k0xmfzo9ycjflojgyjrf5yho6kyh17ra+q0gzjla+vg/gtometrnfqchdshxoqdihdc3khpwrftfbv0lgjmokk0okphp+xpiwgketmbsfwu+zmzkdgesalmloqmj5ka+g4qfgctptprxvty8f0af8btxtskfu7imejtamkdpkjwe7re3i/7rohvlbi5umieopmvuzyrftsc+0z4wwfgohgdccpdxyp+zyrydmwtdpm+wbcmyv8zjbjuwrir8rungzsxgxp/olmafy7t+fvw8u5ywyse5iickiofkhtyrbmkstt7io/kg4vvz/okxmmw6hxmnqdkibydh4oetjc=</latexit> A useful recurrece relatio Divide-ad-coquer recurrece: recursio tree Def. T () = max umber of compares to mergesort a list of legth. Recurrece. T () Solutio. T () is O( log ). 0 =1 T ( / )+T( / ) + >1 betwee / ad 1 compares Assorted proofs. We describe several ways to solve this recurrece. Iitially we assume is a power of ad replace with = i the recurrece. log Propositio. If T () satisfies the followig recurrece, the T () = log. T () = 0 =1 T (/) + >1 T () T ( / ) T ( / ) T ( / 4) T ( / 4) T ( / 4) T ( / 4) assumig is a power of = (/) = 4 (/4) = T ( / 8) T ( / 8) T ( / 8) T ( / 8) T ( / 8) T ( / 8) T ( / 8) T ( / 8) 8 (/8) = 9 T() = log 10 Proof by iductio Divide-ad-coquer: quiz 1 Propositio. If T () satisfies the followig recurrece, the T () = log. T () = Pf. [ by iductio o ] Base case: whe = 1, T(1) = 0 = log. Iductive hypothesis: assume T() = log. Goal: show that T() = log (). iductive hypothesis 0 =1 T (/) + >1 recurrece T() = T() + = log + assumig is a power of Which is the exact solutio of the followig recurrece? T () = A. T() = log B. T() = log C. T() = log + log 1 D. T() = log log + 1 E. Not eve Kuth kows. 0 =1 T ( / ) + T ( / )+ 1 >1 = k=1 log k o loger assumig is a power of = (log () 1) + = log (). 11 1

4 <latexit sha1_base64="plaap4pyckuiob8guiy/wl4ixim=">aaacyicbvfdb9mwfhuyykn8deorlys6ubgijboiqxnoei+8iapzzpqqhkcm86ay0em7wk+syf4wfxb3cytkid98vh51yf+5wwulgxrx+ccofe/qe7ew97jx4/efqsv3/w0+rkcjxylbw5sjlfkrroxasl0qdreglqdxxxv9/bqnfvpn3krepgaljxlbmfpuvp97mlrvgj4aldg8pzriqqiae0+77tgtcf4ddbh0nygcdhv8hvgq1kdpbdtgivepkygvudtaghp/bns0udf96w0bkaoqdbaw0ltw3+5te5rvfxw7w/iezrg3axxb0ykc7o5vvbac00rwpujktm7syospfuzdjbjfqhkosl41dsgtmpfsvqjw7yzw88kwgur8m18pby/77oaftasi9zkfc5dwvi/mzyuxhss1uwtlu/kzqxklwgprdqcymcidxhjbuho8v+cuzjdt/vo0qrxejfgoselkpwxwgw6x0sdys8v4ed3wfro9gku//gwod3u1rlhxpcxzehimia5bs5i1pcg93gxfaxgiffqxuuwvomnqy6p8/jros//gilc9vh</latexit> <latexit sha1_base64="plaap4pyckuiob8guiy/wl4ixim=">aaacyicbvfdb9mwfhuyykn8deorlys6ubgijboiqxnoei+8iapzzpqqhkcm86ay0em7wk+syf4wfxb3cytkid98vh51yf+5wwulgxrx+ccofe/qe7ew97jx4/efqsv3/w0+rkcjxylbw5sjlfkrroxasl0qdreglqdxxxv9/bqnfvpn3krepgaljxlbmfpuvp97mlrvgj4aldg8pzriqqiae0+77tgtcf4ddbh0nygcdhv8hvgq1kdpbdtgivepkygvudtaghp/bns0udf96w0bkaoqdbaw0ltw3+5te5rvfxw7w/iezrg3axxb0ykc7o5vvbac00rwpujktm7syospfuzdjbjfqhkosl41dsgtmpfsvqjw7yzw88kwgur8m18pby/77oaftasi9zkfc5dwvi/mzyuxhss1uwtlu/kzqxklwgprdqcymcidxhjbuho8v+cuzjdt/vo0qrxejfgoselkpwxwgw6x0sdys8v4ed3wfro9gku//gwod3u1rlhxpcxzehimia5bs5i1pcg93gxfaxgiffqxuuwvomnqy6p8/jros//gilc9vh</latexit> <latexit sha1_base64="plaap4pyckuiob8guiy/wl4ixim=">aaacyicbvfdb9mwfhuyykn8deorlys6ubgijboiqxnoei+8iapzzpqqhkcm86ay0em7wk+syf4wfxb3cytkid98vh51yf+5wwulgxrx+ccofe/qe7ew97jx4/efqsv3/w0+rkcjxylbw5sjlfkrroxasl0qdreglqdxxxv9/bqnfvpn3krepgaljxlbmfpuvp97mlrvgj4aldg8pzriqqiae0+77tgtcf4ddbh0nygcdhv8hvgq1kdpbdtgivepkygvudtaghp/bns0udf96w0bkaoqdbaw0ltw3+5te5rvfxw7w/iezrg3axxb0ykc7o5vvbac00rwpujktm7syospfuzdjbjfqhkosl41dsgtmpfsvqjw7yzw88kwgur8m18pby/77oaftasi9zkfc5dwvi/mzyuxhss1uwtlu/kzqxklwgprdqcymcidxhjbuho8v+cuzjdt/vo0qrxejfgoselkpwxwgw6x0sdys8v4ed3wfro9gku//gwod3u1rlhxpcxzehimia5bs5i1pcg93gxfaxgiffqxuuwvomnqy6p8/jros//gilc9vh</latexit> <latexit sha1_base64="plaap4pyckuiob8guiy/wl4ixim=">aaacyicbvfdb9mwfhuyykn8deorlys6ubgijboiqxnoei+8iapzzpqqhkcm86ay0em7wk+syf4wfxb3cytkid98vh51yf+5wwulgxrx+ccofe/qe7ew97jx4/efqsv3/w0+rkcjxylbw5sjlfkrroxasl0qdreglqdxxxv9/bqnfvpn3krepgaljxlbmfpuvp97mlrvgj4aldg8pzriqqiae0+77tgtcf4ddbh0nygcdhv8hvgq1kdpbdtgivepkygvudtaghp/bns0udf96w0bkaoqdbaw0ltw3+5te5rvfxw7w/iezrg3axxb0ykc7o5vvbac00rwpujktm7syospfuzdjbjfqhkosl41dsgtmpfsvqjw7yzw88kwgur8m18pby/77oaftasi9zkfc5dwvi/mzyuxhss1uwtlu/kzqxklwgprdqcymcidxhjbuho8v+cuzjdt/vo0qrxejfgoselkpwxwgw6x0sdys8v4ed3wfro9gku//gwod3u1rlhxpcxzehimia5bs5i1pcg93gxfaxgiffqxuuwvomnqy6p8/jros//gilc9vh</latexit> Aalysis of mergesort recurrece Digressio: sortig lower boud Propositio. If T() satisfies the followig recurrece, the T() log. T () Pf. [ by strog iductio o ] Base case: = 1. Defie 1 = / ad = / ad ote that = 1 +. Iductio step: assume true for 1,,..., 1. iductive hypothesis T() 0 =1 T ( / )+T ( / ) + >1 T( 1) + T( ) + 1 log 1 + log + 1 log + log + = log + ( log 1) + = log. o loger assumig is a power of = d/e d e l m apple d dlog e e l / m = dlog e / d eappled e log appledlog e 1 d eappled e a iteger e Challege. How to prove a lower boud for all coceivable algorithms? Model of computatio. Compariso trees. Ca access the elemets oly through pairwise comparisos. All other operatios (cotrol, data movemet, etc.) are free. Cost model. Number of compares. Q. Realistic model? A1. Yes. Java, Pytho, C++, A. Yes. Mergesort, isertio sort, quicksort, heapsort, A3. No. Bucket sort, radix sorts, Comparable[] a =...;... Arrays.sort(a); ca access elemets oly via calls to compareto() 14 Compariso tree (for 3 distict keys a, b, ad c) Sortig lower boud Theorem. Ay determiistic compare-based sortig algorithm must make yes b < c yes o a < b code betwee compares (e.g., sequece of exchages) yes o a < c height of prued tree = worst-case umber of compares o Ω( log ) compares i the worst-case. Pf. [ iformatio theoretic ] Assume array cosists of distict values a 1 through a. Worst-case umber of compares = height h of prued compariso tree. Biary tree of height h has h leaves.! differet orderigs! reachable leaves. a b c a < c b a c b < c yes o yes o h a c b c a b b c a c b a each reachable leaf correspods to oe (ad oly oe) orderig; exactly oe reachable leaf for each possible orderig 15! leaves h leaves 16

5 Sortig lower boud SHUFFLING A LINKED LIST Theorem. Ay determiistic compare-based sortig algorithm must make Ω( log ) compares i the worst-case. Pf. [ iformatio theoretic ] Assume array cosists of distict values a 1 through a. Worst-case umber of compares = height h of prued compariso tree. Biary tree of height h has h leaves.! differet orderigs! reachable leaves. h # leaves! h log (!) log / l Stirlig s formula Problem. Give a sigly liked list, rearrage its odes uiformly at radom. Assumptio. Access to a perfect radom-umber geerator. Performace. O( log ) time, O(log ) extra space. iput shuffled L ull L ull all! permutatios equally likely Note. Lower boud ca be exteded to iclude radomized algorithms Coutig iversios SECTION DIVIDE AND CONQUER mergesort coutig iversios radomized quicksort media ad selectio closest pair of poits Music site tries to match your sog prefereces with others. You rak sogs. Music site cosults database to fid people with similar tastes. Similarity metric: umber of iversios betwee two rakigs. My rak: 1,,,. Your rak: a 1, a,, a. Sogs i ad j are iverted if i < j, but a i > a j. Brute force: check all Θ( ) pairs. A B C D E me you iversios: 3-, 4-0

6 Coutig iversios: applicatios Coutig iversios: divide-ad-coquer Votig theory. Divide: separate list ito two halves A ad B. Collaborative filterig. Coquer: recursively cout iversios i each list. Measurig the sortedess of a array. Combie: cout iversios (a, b) with a A ad b B. Sesitivity aalysis of Google s rakig fuctio. Retur sum of three couts. Rak aggregatio for meta-searchig o the Web. Noparametric statistics (e.g., Kedall s tau distace). iput 1 Rak Aggregatio Methods for the Web Cythia Dwork Ravi Kumar Moi Naor Rak Aggregatio Methods for the Web Cythia Dwork Ravi Kumar Moi Naor D. Sivakumar cout iversios i left half A D. Sivakumar ABSTRACT cout iversios i right half B ABSTRACT cout iversios (a, b) with a A ad b B 1 1. INTRODUCTION Motivatio Motivatio 1. 8 output = 17 INTRODUCTION Coutig iversios: how to combie two subproblems? Coutig iversios: how to combie two subproblems? Q. How to cout iversios (a, b) with a A ad b B? Cout iversios (a, b) with a A ad b B, assumig A ad B are sorted. A. Easy if A ad B are sorted! Sca A ad B from left to right. Compare ai ad bj. Warmup algorithm. If ai < bj, the ai is ot iverted with ay elemet left i B. Sort A ad B. If ai > bj, the bj is iverted with every elemet left i A. Copyright is held by the author/ower. WWW10, May 1-5, 001, Hog Kog. ACM /01/0005. For each elemet b B, biary search i A to fid how elemets i A are greater tha b. Apped smaller elemet to sorted list C. Copyright is held by the author/ower. WWW10, May 1-5, 001, Hog Kog. ACM /01/ list A 7 list B sort A cout iversios (a, b) with a A ad b B 3 sort B ai 18 3 biary search to cout iversios (a, b) with a A ad b B bj 0 3 merge to form sorted list C

7 <latexit sha1_base64="3pxfe56q7vvcgldq8zgmwt6i7u=">aaachicbvhlattafb0pfatuy0pqpuhtotdwzfciqmmjdawukzbbgiayubjk3viacrmroqn8kkr0m1/pn/tv+liuacexfd4zw799xhuihpmqj+ep7obv37u8+6dx89pjj0+7e/lebl0bawoqqn1cjt6ckhjfkvhbvgobzouayuf5q65ffwfiz6xeuc4gzptmylykjoybd36o+pqrssn/vt4clmjo6eq6ixxxyki3mglwfhtlxlcesskiypqfapychdeuziwykmuuddrklv5bqg+oqbmnlgu/cyvrkuburvadw+l1kjvwby/tegw0nop0m3fwycjugcfvqi1ctpa8ftbnrzmbrqg4tveyfbhx3kauctyqpywcis+g8hbztowcdvsdkvfowzkuzdummukdfvvj4p1i6zxgvmhodu6vj/lrielpxeldlaha3bilpaky0/pmdconcfrlb7gw0vvkxzwbltadc8lqvawjukwpraiwkg6zcbrpebzhc3nkgb8pzgbhl7e989nbvkbxlj+iqkj+scfcyxzeye99wbeh+9t37kf/d/+d9vuv/fomrix/6y+lidpe</latexit> <latexit sha1_base64="3pxfe56q7vvcgldq8zgmwt6i7u=">aaachicbvhlattafb0pfatuy0pqpuhtotdwzfciqmmjdawukzbbgiayubjk3viacrmroqn8kkr0m1/pn/tv+liuacexfd4zw799xhuihpmqj+ep7obv37u8+6dx89pjj0+7e/lebl0bawoqqn1cjt6ckhjfkvhbvgobzouayuf5q65ffwfiz6xeuc4gzptmylykjoybd36o+pqrssn/vt4clmjo6eq6ixxxyki3mglwfhtlxlcesskiypqfapychdeuziwykmuuddrklv5bqg+oqbmnlgu/cyvrkuburvadw+l1kjvwby/tegw0nop0m3fwycjugcfvqi1ctpa8ftbnrzmbrqg4tveyfbhx3kauctyqpywcis+g8hbztowcdvsdkvfowzkuzdummukdfvvj4p1i6zxgvmhodu6vj/lrielpxeldlaha3bilpaky0/pmdconcfrlb7gw0vvkxzwbltadc8lqvawjukwpraiwkg6zcbrpebzhc3nkgb8pzgbhl7e989nbvkbxlj+iqkj+scfcyxzeye99wbeh+9t37kf/d/+d9vuv/fomrix/6y+lidpe</latexit> <latexit sha1_base64="3pxfe56q7vvcgldq8zgmwt6i7u=">aaachicbvhlattafb0pfatuy0pqpuhtotdwzfciqmmjdawukzbbgiayubjk3viacrmroqn8kkr0m1/pn/tv+liuacexfd4zw799xhuihpmqj+ep7obv37u8+6dx89pjj0+7e/lebl0bawoqqn1cjt6ckhjfkvhbvgobzouayuf5q65ffwfiz6xeuc4gzptmylykjoybd36o+pqrssn/vt4clmjo6eq6ixxxyki3mglwfhtlxlcesskiypqfapychdeuziwykmuuddrklv5bqg+oqbmnlgu/cyvrkuburvadw+l1kjvwby/tegw0nop0m3fwycjugcfvqi1ctpa8ftbnrzmbrqg4tveyfbhx3kauctyqpywcis+g8hbztowcdvsdkvfowzkuzdummukdfvvj4p1i6zxgvmhodu6vj/lrielpxeldlaha3bilpaky0/pmdconcfrlb7gw0vvkxzwbltadc8lqvawjukwpraiwkg6zcbrpebzhc3nkgb8pzgbhl7e989nbvkbxlj+iqkj+scfcyxzeye99wbeh+9t37kf/d/+d9vuv/fomrix/6y+lidpe</latexit> <latexit sha1_base64="3pxfe56q7vvcgldq8zgmwt6i7u=">aaachicbvhlattafb0pfatuy0pqpuhtotdwzfciqmmjdawukzbbgiayubjk3viacrmroqn8kkr0m1/pn/tv+liuacexfd4zw799xhuihpmqj+ep7obv37u8+6dx89pjj0+7e/lebl0bawoqqn1cjt6ckhjfkvhbvgobzouayuf5q65ffwfiz6xeuc4gzptmylykjoybd36o+pqrssn/vt4clmjo6eq6ixxxyki3mglwfhtlxlcesskiypqfapychdeuziwykmuuddrklv5bqg+oqbmnlgu/cyvrkuburvadw+l1kjvwby/tegw0nop0m3fwycjugcfvqi1ctpa8ftbnrzmbrqg4tveyfbhx3kauctyqpywcis+g8hbztowcdvsdkvfowzkuzdummukdfvvj4p1i6zxgvmhodu6vj/lrielpxeldlaha3bilpaky0/pmdconcfrlb7gw0vvkxzwbltadc8lqvawjukwpraiwkg6zcbrpebzhc3nkgb8pzgbhl7e989nbvkbxlj+iqkj+scfcyxzeye99wbeh+9t37kf/d/+d9vuv/fomrix/6y+lidpe</latexit> Coutig iversios: divide-ad-coquer algorithm implemetatio Coutig iversios: divide-ad-coquer algorithm aalysis Iput. List L. Output. Number of iversios i L ad L i sorted order. Propositio. The sort-ad-cout algorithm couts the umber of iversios i a permutatio of size i O( log ) time. Pf. The worst-case ruig time T() satisfies the recurrece: SORT-AND-COUNT(L) IF (list L has oe elemet) RETURN (0, L). T () = (1) =1 T ( / ) + T ( / ) + () >1 Divide the list ito two halves A ad B. (r A, A) SORT-AND-COUNT(A). (r B, B) SORT-AND-COUNT(B). (r AB, L) MERGE-AND-COUNT(A, B). T( / ) T( / ) Θ() RETURN (r A + r B + r AB, L) WAY PARTITIONING 5. DIVIDE AND CONQUER mergesort coutig iversios radomized quicksort media ad selectio closest pair of poits Goal. Give a array A ad pivot elemet p, partitio array so that: Smaller elemets i left subarray L. Equal elemets i middle subarray M. Larger elemets i right subarray R. Challege. O() time ad O(1) space. the array A SECTION p the partitioed array A L M R 8

8 Radomized quicksort Radomized quicksort Pick a radom pivot elemet p A. 3-way partitio the array ito L, M, ad R. Recursively sort both L ad R. Pick a radom pivot elemet p A. 3-way partitio the array ito L, M, ad R. Recursively sort both L ad R. the array A partitio A sort L p RANDOMIZED-QUICKSORT(A) IF (array A has zero or oe elemet) RETURN. Pick pivot p A uiformly at radom. (L, M, R) PARTITION-3-WAY(A, p). Θ() sort R RANDOMIZED-QUICKSORT(L). RANDOMIZED-QUICKSORT(R). T(i) T( i 1) ew aalysis required (i is a radom variable depeds o p) the sorted array A Aalysis of radomized quicksort Aalysis of radomized quicksort Propositio. The expected umber of compares to quicksort a array of distict elemets a 1 < a < < a is O( log ). Pf. Cosider BST represetatio of pivot elemets. Propositio. The expected umber of compares to quicksort a array of distict elemets a 1 < a < < a is O( log ). Pf. Cosider BST represetatio of pivot elemets. a i ad a j are compared oce iff oe is a acestor of the other. the origial array of elemets A a 7 a 6 a 1 a 3 a 11 a 8 a 9 a 1 a 4 a 10 a a 13 a 5 first pivot i left subarray first pivot (chose uiformly at radom) first pivot i left subarray first pivot (chose uiformly at radom) a3 ad a6 are compared (whe a3 is pivot) a9 a9 a3 a11 a3 a11 a1 a8 a10 a13 a1 a8 a10 a13 a a 4 a 1 a a 4 a 1 a 6 a 6 a 5 a 7 31 a 5 a 7 3

9 Aalysis of radomized quicksort Divide-ad-coquer: quiz Propositio. The expected umber of compares to quicksort a array of distict elemets a1 < a < < a is O( log ). Give a array of 8 distict elemets a1 < a < < a, what is the probability that a7 ad a8 are compared durig radomized quicksort? Pf. Cosider BST represetatio of pivot elemets. a i ad a j are compared oce iff oe is a acestor of the other. A. 0 B. 1 / C. / first pivot i left subarray first pivot (chose uiformly at radom) a ad a8 are ot compared (because a3 partitios them) D. 1 if two elemets are adjacet, oe must be a acestor of the other a9 a9 a3 a11 a3 a11 a1 a8 a10 a13 a1 a8 a10 a13 a a4 a1 a a4 a1 a6 a6 a5 a7 33 a5 a7 34 Divide-ad-coquer: quiz 3 Aalysis of radomized quicksort Give a array of distict elemets a 1 < a < < a, what is the probability that a 1 ad a are compared durig radomized quicksort? Propositio. The expected umber of compares to quicksort a array of distict elemets a 1 < a < < a is O( log ). A. 0 B. 1 / Pf. Cosider BST represetatio of pivot elemets. a i ad a j are compared oce iff oe is a acestor of the other. Pr [ a i ad a j are compared ] = / ( j - i + 1), where i < j. C. / a1 ad a are compared iff first pivot is either a1 or a D. 1 Pr[a ad a8 compared] = /7 compared iff either a or a8 is chose as pivot before ay of { a3, a4, a5, a6, a7} a9 a9 a3 a11 a3 a11 a1 a8 a10 a13 a1 a8 a10 a13 a a 4 a 1 a a 4 a 1 a 6 a 6 a 5 a 7 35 a 5 a 7 36

10 Aalysis of radomized quicksort Toy Hoare u m b e r ). 9.9 X is u s e d to r e p r e s e t i f i i t y. I m a g i a r y v a l u e s of x m a y o t be e g a t i v e a d rem v a l u e s of x m a y o t be s m a l l e r t h a 1. V a l u e s of Qd~'(x) m a y be c a l c u l a t e d e a s i l y by h y p e r g e o m e t r i c series if x is o t t o o s m a l l o r ( - m ) t o o large. Q~m(x) c a be c o m p u t e d f r o m a a p p r o p r i a t e set of v a l u e s of Pm(X) if X is e a r 1.0 or ix is e a r 0. L o s s of s i g i f i c a t d i g i t s o c c u r s for x as s m a l l as 1.1 if is l a r g e r t h a 10. L o s s of s i g i f i c a t d i g i t s is a m a j o r diffic u l t y i u s i g fiite p o l y o m i M r e p r e s e t a t i o s also if is l a r g e r t h a m. H o w e v e r, Q L E G h a s b e e t e s t e d i r e g i o s of x a d b o t h large a d small; procedure Q L E G ( m, m a x, x, ri, R, Q); v a l u e I, m a x, x, ri; r e a l I, m a x, x, ri; r e a l a r r a y R, Q; r e a l t, i,, q0, s; : = 0; i f m a x > 13 t h e := max +7; i f ri = 0 t h e ifm = 0the Q[0] : = 0.5 X 10g((x + 1 ) / ( x - 1)) else t : = / s q r t ( x X x - - 1); q0 : = 0; Q[O] : = t ; for i : = 1 step 1 util m do s := (x+x)x(i-1)xt Q[0]+ (3i-i i-) q0; q0 : = Q[0]; Q[0] : = s e d e d ; if x = 1 the Q[0] : = 9.9 I" 45; R [ + 1] : = x - s q r t ( x X x - 1); for i : = s t e p --1 u t i l 1 d o R[i] : = (i + m ) / ( ( i + i + 1) X x +(m-i1) X R [ i + l ] ) ; g o to t h e e d ; if m = 0 the b e g i i f x < 0.5 t b e Q[0] : = a r c t a ( x ) e l s e Q[0] : = - a r e t a ( 1 / x ) e d e l s e t : = 1 / s q r t ( x X x + 1); q0 : = 0; Propositio. The expected umber of compares to quicksort a array of distict elemets a1 < a < couet I a d J are o u t p u t v a r i a b l e s, a d A is t h e a r r a y ( w i t h s u b s c r i p t b o u d s M : N ) w h i c h is o p e r a t e d u p o b y t h i s p r o c e d u r e. P a r t i t i o t a k e s t h e v a l u e X of a r a d o m e l e m e t of t h e a r r a y A, a d r e a r r a g e s t h e v a l u e s of t h e e l e m e t s of t h e a r r a y i s u c h a w a y t h a t t h e r e e x i s t i t e g e r s I a d J w i t h t h e followig p r o p e r t i e s : M _-< J < I =< N p r o v i d e d M < N A[R] =< X f o r M =< R _-< J A[R] = X f o r J < R < I A[R] ~ X f o r I =< R ~ N The procedure uses a iteger procedure radom (M,N) which chooses equiprobably a radom iteger F betwee M ad N, ad also a p r o c e d u r e e x c h a g e, w h i c h e x c h a g e s t h e v a l u e s of its t w o parameters ; real X; iteger F; F : = r a d o m ( M, N ) ; X : = A[F]; I:=M; J:=N; for I : = I s t e p 1 u t i l N d o up: i f X < A [I] t h e g o to d o w ; I:=N; dow: f o r J : = J s t e p --1 u t i l M d o if A[J]<X the go to chage; J:=M; c h a g e : i f I < J t h e b e g i e x c h a g e (A[IL A[J]); I := I+ 1;J:= J - 1; g o to u p ed 4 else i f [ < F t h e b e g i e x c h a g e (A[IL A[F]) i I:=I+l ed else i f F < J t l l e b e g i e x c h a g e (A[F], A[J]) ; J:=J-1 ed ; ed partitio Iveted quicksort to traslate Russia ito Eglish. < a is O( log ). [ but could t explai his algorithm or implemet it! ] Leared Algol 60 (ad recursio). Pf. Cosider BST represetatio of pivot elemets. Implemeted quicksort. ai ad aj are compared oce iff oe is a acestor of the other. Pr [ ai ad aj are compared ] = / ( j - i + 1), where i < j. i=1 i=1 j=i+1 j=i+1 i=1 j=i+1 i=1 j=i+1 Expected umber of compares = all pairs i ad j <latexit sha1_base64="tsqczvbieugfpzvbrgcekd3sgfa=">aaadbhicjzfnb9naeibxlh8lfkxlygvebcoqrlzvivzrpsiuhiteakvsinabcbrteu3urlejyd+dsfelf+b+dos7ycsfcfgsvzumzpvjnxlowxqfdd8zdu3lx1e/no5+69+w8edrep5is0byhpjozpozqskudqwek9zjsynjz7ef/q/mk1ezk6rd5zhouyjrhbmhzp0f1jtpjnshibvx1jvqf9as87hemsuo6phiwa8jkry/gun4rqar4kuyvafzljqpz/fhkrw7kg7v6oxfzapjz6l/z+p8ao1qqulal4fnjtxf0gybguggxokcwctzz8rbpnonfispyyywzhufuxyxtvcjvycwbpgl9gmr04qlqizl80wkjqybsstlthwwjockfjumpmaewqubpzhquh/ljqqb7i9loflcoultrukhwwzqrxsmqio3cu4e41q4bwv+xty0rfv8yind4585u/kq0ijk1xjup7ztwr3btd9zldf8oof9ap3+31jvyx49wkj8ktsknc8oockbfkmawj9157my/3lv3p/hf/q/+tlfw9rc8jshl+91/5ze5</latexit> <latexit sha1_base64="gjzqomht99byyg9epbf0urts8xc=">aaadbhicjzfdb9mwfiad8dxkx7pxyc0rfwhotiojjdzvk4a44xjileqs+w4tufncylttkusxo/x7apxy/9a/bmctiiq4gjrx9hnej+ckhrtgrtgpilx1+87dexv3ww8epq8d7a/mtyujm+ylm9ulcdzdc8yevvvktqoajzifj+fv6vzxbddg5oqjrv8lngpeqlg1ho0bv8kpszgthzg6rntfzbxmcdcabi11pvsfrt5ulkxvff1fwakif9h1j84ob/mut16xbm/xwt7kh0rtxwrfc4gvku9s37/09ehhsivkngf/hlc7ks9qam4kfbcdnaijszbwtaz5kzmuljmumogocrsyfftbzo8aphs8ikyczrlqy8vzbgzuwylftz3zajprvjldr0ucprzjhzlvjkjnpts56r4d9yw9kmeymvffartj8orsuyhoovwototmzcuyfzvr4bwvsv0rf/8yind8hzyp+4y1ijlk/4gpx0mpa+si9zdfio4t9/dh153dvcw49xat9eztimweomo0xt0haaibw+davaex8kr8dr8g6bl4bboucjwow+y/+pe7</latexit> j j j i+ 1 i 1 i 1 = = = i+1 i+1 i+1 1 i+1 1 j1 i=1 j= j= j i=1 i=1 j= j i=1 j= 1 1 j1 j=1 j j=1 j=1 j j=1 1 1) (l + q[0] := t; 1 dx (l x dx + 1) x=1 x=1 x = l = l for R[ + for harmoic sum Remark. Number of compares oly decreases if equal elemets. ALGORITHM for the: for i : = ed QLEG; 61 P R O C E D U R E S 64F O R R A N G E A R I T H M E T I C ALGORITHM ALLAN GIBB* QUICKSORT U ia. v e r sr. i t y HOARE of A l b e r t a, C a l g a r y, A l b e r t a, C a a d a C. Elliott b e g i Brothers Ltd., Borehamwood, Hertfordshire, Eg. i : = step 1 util m do b e g i s : = (x + x) X (i -- 1) X t X Q[0I +(3i+iX i -- ) q0; qo : = Q[0]; Q[0] := s e d e d ; 1] : = x - s q r t ( x x + 1); i := step - 1 util 1 do R[i] : = (i + m ) / ( ( i -- m + 1) R[i + 1] --(i+i+ 1) X x); i : = 1 step util max do Rill : = -- Rill; 1 step 1 util mx do Q[i] : = Q[i - 1] X R[i] * T h i s p r o c e d u r e w a s d e v e l o p e d i p a r t u d e r t h e s p o s o r s h i p of t h e A i r F o r c e C a m b r i d g e R e s e a r c h C e t e r. p r o c e d u r e R A N G E S U M (a, b, c, d, e, f); procedure quicksort (A,M,N); value M,N; real a, b, c, d, e, f ; a r r a y A; i t e g e r M, N ; c o m m e t The term "rage u m b e r " was used by P. S. Dwyer, Q u i c k s o r t is a v e r y f a s t a d c o v e i e t m e t h o d of commet Liear Computatios (Wiley, 1951). Machie procedures for s o r t i g a a r r a y i t h e r a d o m - a c c e s s s t o r e of a c o m p u t e r. T h e rage arithmetic were developed about 1958 by Ramo Moore, e t i r e c o t e t s of t h e s t o r e m a y be s o r t e d, sice o e x t r a s p a c e is "Automatic Error Aalysis i Digital C o m p u t a t i o, " LMSD r e q u i r e d. T h e a v e r a g e u m b e r of c o m p a r i s o s m a d e is ( M - - N ) I Report 4841, 8 Ja. 1959, Lockheed Missiles ad Space Divi( N - - M ), a d t h e a v e r a g e m b e r of e x c h a g e s is oe s i x t h t h i s sio, Palo Alto, Califoria, 59 pp. If a _< x -< b ad c ~ y ~ d, a m o u t. S u i t a b l e r e f i e m e t s of t h i s m e t h o d will be d e s i r a b l e for the R A N G E S U M yields a iterval [e, f] such t h a t e =< (x + y) its i m p l e m e t a t i o o a y a c t u a l c o m p u t e r ; f. Because of machie operatio (trucatio or roudig) the i t e g e r 1,J ; machie sums a -4- c ad b -4- d may ot provide safe ed-poits if M < N the partitio (A,M,N,I,J); of the output iterval. Thus R A N G E S U M requires a o-local quicksort (A,M,J) ; real procedure A D J U S T S U M which will compesate for the q u i c k s o r t (A, I, N ) machie arithmetic. The body of A D J U S T S U M will be deed pedet upo the type of machie for which it is writte ad so ed quieksort is ot give here. (A example, however, appears below.) I t is assumed t h a t A D J U S T S U M has as parameters real v ad w, ad iteger i, ad is accompaied by a o-local real procedure C O R R E C T I O N 65 which gives a upper boud to the magitude ALGORITHM of the error ivolved i the machie represetatio of a umber. FIND The output A D J U S T S U M provides the left ed-poit of the C.output A. R.iterval HOARE of R A N G E S U M whe A D J U S T S U M is called Elliott Borehamwood, Hertfordshire, with i Brothers = --1, adltd., the right ed-poit whe called with i Eg. = 1 The procedures RANGESUB, R A N G E M P Y, ad R A N G E D V D procedure fid ( A, M, N, K ) ; v a l u e M, N, K ; provide for the remaiig fudametal operatios i rage a r r a y A; i t e g e r M, N, K ; arithmetic. R A N G E S Q R gives a iterval withi which the commet F i d will a s s i g to A [K] t h e v a l u e w h i c h it w o u l d square of a rage mber must lie. R N G S U M C, RNGSUBC, h a v e if t h e a r r a y A [ M : N ] h a d b e e s o r t e d. T h e a r r a y A will be R N G M P Y C ad R N G D V D C provide for rage arithmetic with p a r t l y s o r t e d, a d s u b s e q u e t e t r i e s will be f a s t e r t h a t h e first; complex rage argumets, i.e. the real ad imagiary parts are rage umbers~ Commuicatios of the ACM 31 Commuicatios of the ACM (July 1961) 37 ALGORITHM 63 PARTITION C. A. R. HOARE Elliott Brothers Ltd., Borehamwood, Hertfordshire, Eg. procedure NUTS AND BOLTS partitio (A,M,N,I,J); value M,N; a r r a y A; i t e g e r M, N, 1, J ; e : = A D J U S T S U M (a, c, - 1 ) ; f : = A D J U S T S U M (b, d, 1) ed RANGESUM; p r o c e d u r e R A N G E S U B (a, b, c, d, e, f) ; real a, b, c, d, e, f; c o m m e t R A N G E S U M is a o-local procedure; R A N G E S U M (a, b, - d, --c, e, f) ed RANGESUB ; p r o c e d u r e R A N G E M P Y (a, b, c, d, e, f); real a, b, c, d, e, f; c o m m e t A D J U S T P R O D, which appears at the ed of this procedure, is aalogous to A D J U S T S U M above ad is a olocal real procedure. M A X ad M I N fid the maximum ad miimum of a set of real umbers ad are o-local; real v, w; i f a < 0 A c => 0 t h e 1: b e g i v:=c; c:=a; a:=v; w:=d; d:=b; b:=w e d 1; i f a => O t h e 5. D IVIDE Problem. A disorgaized carpeter has a mixed pile of uts ad bolts. The goal is to fid the correspodig pairs of uts ad bolts. mergesort Each ut fits exactly oe bolt ad each bolt fits exactly oe ut. AND Toy Hoare 1980 Turig Award : b e g i i f c >= 0 t h e 3: e:= axe;f := bxd;goto8 ed 3 ; e:=bxc; ifd ~ 0the 4: f:=bxd; goto8 e d 4; f:=axd; goto8 5: e d ; ifb > 0 the 6: b e g i if d > 0 the e : = M I N ( a X d, b X c); f : = M A X ( a X c, b X d); go t o 8 e d 6; e : = b X c; f : = a X c; go t o 8 e d 5; f:=axc; i f d _-<O t h e 7: b e g i e:=bxd; goto8 ed 7 ; e:=axd; 8: e : = A D J U S T P R O D (e, - 1 ) ; f := A D J U S T P R O D (f, 1) ed RANGEMPY; p r o c e d u r e R A N G E D V D (a, b, c, d, e, f) ; real a, b, c, d, e, f; c o m m e t If the rage divisor icludes zero the program exists to a o-local label " z e r o d v s r ". R A N G E D V D assumes a o-local real procedure A D J U S T Q U O T which is aalogous (possibly idetical) to A D J U S T P R O D ; 38 i f c =< 0 A d ~ 0 t h e go to zer0dvsr; if c < 0 the 1: b e g i ifb > 0 the : e : = b / d ; go t o 3 e d ; e := b/c; 3: i f a -->_0 t h e 4: f : = a / c ; go t o 8 e d 4; f : = a / d ; go t o 8 ed 1; if a < 0 the 5: b e g i e : = a/c; go t o 6 ed 5 ; e := a/d; 6: i f b > 0 t h e 7: b e g i f : = b / c ; go t o 8 ed 7 ; f := b/d; 8: e : = ADJUSTQUOT (e, - 1 ) ; f : = ADJUSTQUOT (f,1) ed RANGEDVD ; p r o c e d u r e R A N G E S Q R (a, b, e, f); r e a l a, b, e, f; c o m m e t A D J U S T P R O D is a o-10cal procedure; if a < 0 the C ONQUER coutig iversios By fittig a ut ad a bolt together, the carpeter ca see which oe is bigger (but caot directly compare either two uts or two bolts). radomized quicksort media ad selectio closest pair of poits SECTION 9.3 Brute-force solutio. Compare each bolt to each ut Θ ( ) compares. Challege. Desig a algorithm that makes O( log ) compares. 39 C o m m u i c a t i o s o f t h e &CM 319

11 Media ad selectio problems Radomized quickselect Selectio. Give elemets from a totally ordered uiverse, fid k th smallest. Miimum: k = 1; maximum: k =. Media: k = ( + 1) /. O() compares for mi or max. O( log ) compares by sortig. O( log k) compares with a biary heap. max heap with k smallest Pick a radom pivot elemet p A. 3-way partitio the array ito L, M, ad R. Recur i oe subarray the oe cotaiig the k th smallest elemet. Applicatios. Order statistics; fid the top k ; bottleeck paths, Q. Ca we do it with O() compares? A. Yes! Selectio is easier tha sortig. QUICK-SELECT(A, k) Pick pivot p A uiformly at radom. (L, M, R) PARTITION-3-WAY(A, p). Θ() IF (k L ) RETURN QUICK-SELECT(L, k). T(i) ELSE IF (k > L + M ) RETURN QUICK-SELECT(R, k L M ) ELSE IF (k = L ) RETURN p. T( i 1) Radomized quickselect aalysis Selectio i worst-case liear time Ituitio. Split cady bar uiformly expected size of larger piece is ¾. Def. T(, k) = expected # compares to select k th smallest i array of legth. Def. T() = max k T(, k). T() T(3 / 4) + T() 4 ot rigorous: ca t assume E[T(i)] T(E[i]) Goal. Fid pivot elemet p that divides list of elemets ito two pieces so that each piece is guarateed to have 7/10 elemets. Q. How to fid approximate media i liear time? A. Recursively compute media of sample of /10 elemets. Propositio. T() 4. Pf. [ by strog iductio o ] Assume true for 1,,, 1. T() satisfies the followig recurrece: ca assume we always recur of larger of two subarrays sice T() is mootoe o-decreasig T() = Θ(1) if = 1 T (7/10 ) + T (/10 ) + Θ() two subproblems of differet sizes! otherwise T() + 1 / [ T( / ) + + T( 3) + T( ) + T( 1) ] + 1 / [ 8( / ) + + 8( 3) + 8( ) + 8( 1) ] + 1 / (3 ) = 4. tiy cheat: sum should start at T( / ) iductive hypothesis T() = Θ() we ll eed to show this 45 46

12 Choosig the pivot elemet Choosig the pivot elemet Divide elemets ito / 5 groups of 5 elemets each (plus extra). Divide elemets ito / 5 groups of 5 elemets each (plus extra). Fid media of each group (except extra). medias = = Choosig the pivot elemet Media-of-medias selectio algorithm Divide elemets ito / 5 groups of 5 elemets each (plus extra). Fid media of each group (except extra). Fid media of / 5 medias recursively. Use media-of-medias as pivot elemet. medias MOM-SELECT(A, k) A. IF ( < 50) RETURN k th smallest of elemet of A via mergesort. media of medias Group A ito / 5 groups of 5 elemets each (igore leftovers) B media of each group of 5. p MOM-SELECT(B, / 10 ) media of medias (L, M, R) PARTITION-3-WAY(A, p) IF (k L ) RETURN MOM-SELECT(L, k). ELSE IF (k > L + M ) RETURN MOM-SELECT(R, k L M ) ELSE RETURN p. =

13 Aalysis of media-of-medias selectio algorithm Aalysis of media-of-medias selectio algorithm At least half of 5-elemet medias p. At least half of 5-elemet medias p. At least / 5 / = / 10 medias p. medias medias p media of medias p media of medias p = = 54 5 Aalysis of media-of-medias selectio algorithm Aalysis of media-of-medias selectio algorithm At least half of 5-elemet medias p. At least / 5 / = / 10 medias p. At least 3 / 10 elemets p. At least half of 5-elemet medias p. medias p medias media of medias p media of medias p = = 54 54

14 Aalysis of media-of-medias selectio algorithm Aalysis of media-of-medias selectio algorithm At least half of 5-elemet medias p. At least / 5 / = / 10 medias p. At least half of 5-elemet medias p. At least / 5 / = / 10 medias p. At least 3 / 10 elemets p. medias p medias p media of medias p media of medias p = = Media-of-medias selectio algorithm recurrece Media-of-medias selectio algorithm recurrece Media-of-medias selectio algorithm recurrece. Media-of-medias selectio algorithm recurrece. Select called recursively with / 5 elemets to compute MOM p. Select called recursively with / 5 elemets to compute MOM p. At least 3 / 10 elemets p. At least 3 / 10 elemets p. At least 3 / 10 elemets p. At least 3 / 10 elemets p. Select called recursively with at most 3 / 10 elemets. Select called recursively with at most 3 / 10 elemets. Def. C() = max # compares o ay array of elemets. Def. C() = max # compares o ay array of elemets. C() C ( /5 ) + C ( 3 /10 ) C() C ( /5 ) + C ( 3 /10 ) media of medias recursive select computig media of 5 ( 6 compares per group) media of medias recursive select computig media of 5 ( 6 compares per group) partitioig ( compares) partitioig ( compares) Ituitio. Now, let s solve give recurrece. C() is goig to be at least liear i C() is super-additive. Assume is both a power of 5 ad a power of 10? Igorig floors, this implies that C() C( / / 10) + 11/5 Prove that C() is mootoe o-decreasig. = C(9 / 10) + 11/5 C()

15 <latexit sha1_base64="y96hacevn4aord6hbv5tphcoy0y=">aaac0icbvhlbtnafbbvwmppmxj5ooilaorbccikkjuyozlktctllgi8fg6hxu8tmbgkjgvbwllj/bj/a1j1xjnwl0dxof5yalfmygwr/pv3x7zt17e/d7dx4+erzfpzj8zopkc4x4iqt9ktcduiimrlasl0qnle8kidx00y//47aiej9tass45wtlmgez9zr8/7v6vadaz18pjmetxahvm1do7pu0ukal4baxfqoqwswbgvuiora6szephyp0ygvmswkder1gkhu8rg8bncwxsfb+cehwudzprxogzx9bjpuzpopb3to6jsbqf5fxcmgjzgf4qdgjauzuyh3ifnc17lqcyxzjhzgjqrpmgkt0f1ygs8avajdiqwo4r1tm1phdmcplbpsuuhza9wvgz3jhvrjmnlls6015p+0wwwz47gwqqwsk49kkskakab0eqnhirvw4wroxbffglc5z98ankw3vevgjfwyuoixkw6x0i6tzol4bzuyb6m/owcr+8g5wed3bukafkgrmsklwp+qzosmr4d6+n/zove9+5nf+d//darvdtvpyeb4v/4ck0dzrw==</latexit> <latexit sha1_base64="y96hacevn4aord6hbv5tphcoy0y=">aaac0icbvhlbtnafbbvwmppmxj5ooilaorbccikkjuyozlktctllgi8fg6hxu8tmbgkjgvbwllj/bj/a1j1xjnwl0dxof5yalfmygwr/pv3x7zt17e/d7dx4+erzfpzj8zopkc4x4iqt9ktcduiimrlasl0qnle8kidx00y//47aiej9tass45wtlmgez9zr8/7v6vadaz18pjmetxahvm1do7pu0ukal4baxfqoqwswbgvuiora6szephyp0ygvmswkder1gkhu8rg8bncwxsfb+cehwudzprxogzx9bjpuzpopb3to6jsbqf5fxcmgjzgf4qdgjauzuyh3ifnc17lqcyxzjhzgjqrpmgkt0f1ygs8avajdiqwo4r1tm1phdmcplbpsuuhza9wvgz3jhvrjmnlls6015p+0wwwz47gwqqwsk49kkskakab0eqnhirvw4wroxbffglc5z98ankw3vevgjfwyuoixkw6x0i6tzol4bzuyb6m/owcr+8g5wed3bukafkgrmsklwp+qzosmr4d6+n/zove9+5nf+d//darvdtvpyeb4v/4ck0dzrw==</latexit> <latexit sha1_base64="y96hacevn4aord6hbv5tphcoy0y=">aaac0icbvhlbtnafbbvwmppmxj5ooilaorbccikkjuyozlktctllgi8fg6hxu8tmbgkjgvbwllj/bj/a1j1xjnwl0dxof5yalfmygwr/pv3x7zt17e/d7dx4+erzfpzj8zopkc4x4iqt9ktcduiimrlasl0qnle8kidx00y//47aiej9tass45wtlmgez9zr8/7v6vadaz18pjmetxahvm1do7pu0ukal4baxfqoqwswbgvuiora6szephyp0ygvmswkder1gkhu8rg8bncwxsfb+cehwudzprxogzx9bjpuzpopb3to6jsbqf5fxcmgjzgf4qdgjauzuyh3ifnc17lqcyxzjhzgjqrpmgkt0f1ygs8avajdiqwo4r1tm1phdmcplbpsuuhza9wvgz3jhvrjmnlls6015p+0wwwz47gwqqwsk49kkskakab0eqnhirvw4wroxbffglc5z98ankw3vevgjfwyuoixkw6x0i6tzol4bzuyb6m/owcr+8g5wed3bukafkgrmsklwp+qzosmr4d6+n/zove9+5nf+d//darvdtvpyeb4v/4ck0dzrw==</latexit> <latexit sha1_base64="y96hacevn4aord6hbv5tphcoy0y=">aaac0icbvhlbtnafbbvwmppmxj5ooilaorbccikkjuyozlktctllgi8fg6hxu8tmbgkjgvbwllj/bj/a1j1xjnwl0dxof5yalfmygwr/pv3x7zt17e/d7dx4+erzfpzj8zopkc4x4iqt9ktcduiimrlasl0qnle8kidx00y//47aiej9tass45wtlmgez9zr8/7v6vadaz18pjmetxahvm1do7pu0ukal4baxfqoqwswbgvuiora6szephyp0ygvmswkder1gkhu8rg8bncwxsfb+cehwudzprxogzx9bjpuzpopb3to6jsbqf5fxcmgjzgf4qdgjauzuyh3ifnc17lqcyxzjhzgjqrpmgkt0f1ygs8avajdiqwo4r1tm1phdmcplbpsuuhza9wvgz3jhvrjmnlls6015p+0wwwz47gwqqwsk49kkskakab0eqnhirvw4wroxbffglc5z98ankw3vevgjfwyuoixkw6x0i6tzol4bzuyb6m/owcr+8g5wed3bukafkgrmsklwp+qzosmr4d6+n/zove9+5nf+d//darvdtvpyeb4v/4ck0dzrw==</latexit> <latexit sha1_base64="uctptmzk5kuvff1msqyvcmsiy=">aaac9hicbvfnj9mwehxc11k+usury4gk1aqxebhutmsxixjirv0pboqjjvpwus4ke1aq6g/hrpiyh/hf/bvcnjkbfvm9pteeobnc5wrav0u/qca9dv3lx1cltx5+69+w+ah0efbvyyguorqcycx9yikhqhtjqf57lbsykr/hlh0offuvjzayhbpjjovzlrmpupputpl70nydyhmkpublma51kxwa+qwfpvndwf5dhoaszwao0videbiynkayt3wis5qtgpz8bftyx7tz3cnbmklfzzkc/6aezne7as6ofjuev/jnpdfviegiphrv9vyyyhmw1b4jnse1jqzdpdsyjzbuteqc/yb3yawdtz9da4yrnmfclqjxs3dkyj3e1kbpwuc0chcwci0s+x7ghmqdojwd+gqeegygit8iybsdmr36ousptcs09p0pdxdv6vi/jwiuk1lqvhcoxxpruihwgvrfcdnpudi19iali71xebfc5+b8r9tqwfklyukreflikb4q6r3mizxqvidzpbb8ox3xdd+ul16/rke+cbeuqekzah5c05jr/jgrksedbgfhwjepgt/b7+ch+uw8ng8+yharw118pf+rq</latexit> <latexit sha1_base64="uctptmzk5kuvff1msqyvcmsiy=">aaac9hicbvfnj9mwehxc11k+usury4gk1aqxebhutmsxixjirv0pboqjjvpwus4ke1aq6g/hrpiyh/hf/bvcnjkbfvm9pteeobnc5wrav0u/qca9dv3lx1cltx5+69+w+ah0efbvyyguorqcycx9yikhqhtjqf57lbsykr/hlh0offuvjzayhbpjjovzlrmpupputpl70nydyhmkpublma51kxwa+qwfpvndwf5dhoaszwao0videbiynkayt3wis5qtgpz8bftyx7tz3cnbmklfzzkc/6aezne7as6ofjuev/jnpdfviegiphrv9vyyyhmw1b4jnse1jqzdpdsyjzbuteqc/yb3yawdtz9da4yrnmfclqjxs3dkyj3e1kbpwuc0chcwci0s+x7ghmqdojwd+gqeegygit8iybsdmr36ousptcs09p0pdxdv6vi/jwiuk1lqvhcoxxpruihwgvrfcdnpudi19iali71xebfc5+b8r9tqwfklyukreflikb4q6r3mizxqvidzpbb8ox3xdd+ul16/rke+cbeuqekzah5c05jr/jgrksedbgfhwjepgt/b7+ch+uw8ng8+yharw118pf+rq</latexit> <latexit sha1_base64="uctptmzk5kuvff1msqyvcmsiy=">aaac9hicbvfnj9mwehxc11k+usury4gk1aqxebhutmsxixjirv0pboqjjvpwus4ke1aq6g/hrpiyh/hf/bvcnjkbfvm9pteeobnc5wrav0u/qca9dv3lx1cltx5+69+w+ah0efbvyyguorqcycx9yikhqhtjqf57lbsykr/hlh0offuvjzayhbpjjovzlrmpupputpl70nydyhmkpublma51kxwa+qwfpvndwf5dhoaszwao0videbiynkayt3wis5qtgpz8bftyx7tz3cnbmklfzzkc/6aezne7as6ofjuev/jnpdfviegiphrv9vyyyhmw1b4jnse1jqzdpdsyjzbuteqc/yb3yawdtz9da4yrnmfclqjxs3dkyj3e1kbpwuc0chcwci0s+x7ghmqdojwd+gqeegygit8iybsdmr36ousptcs09p0pdxdv6vi/jwiuk1lqvhcoxxpruihwgvrfcdnpudi19iali71xebfc5+b8r9tqwfklyukreflikb4q6r3mizxqvidzpbb8ox3xdd+ul16/rke+cbeuqekzah5c05jr/jgrksedbgfhwjepgt/b7+ch+uw8ng8+yharw118pf+rq</latexit> <latexit sha1_base64="uctptmzk5kuvff1msqyvcmsiy=">aaac9hicbvfnj9mwehxc11k+usury4gk1aqxebhutmsxixjirv0pboqjjvpwus4ke1aq6g/hrpiyh/hf/bvcnjkbfvm9pteeobnc5wrav0u/qca9dv3lx1cltx5+69+w+ah0efbvyyguorqcycx9yikhqhtjqf57lbsykr/hlh0offuvjzayhbpjjovzlrmpupputpl70nydyhmkpublma51kxwa+qwfpvndwf5dhoaszwao0videbiynkayt3wis5qtgpz8bftyx7tz3cnbmklfzzkc/6aezne7as6ofjuev/jnpdfviegiphrv9vyyyhmw1b4jnse1jqzdpdsyjzbuteqc/yb3yawdtz9da4yrnmfclqjxs3dkyj3e1kbpwuc0chcwci0s+x7ghmqdojwd+gqeegygit8iybsdmr36ousptcs09p0pdxdv6vi/jwiuk1lqvhcoxxpruihwgvrfcdnpudi19iali71xebfc5+b8r9tqwfklyukreflikb4q6r3mizxqvidzpbb8ox3xdd+ul16/rke+cbeuqekzah5c05jr/jgrksedbgfhwjepgt/b7+ch+uw8ng8+yharw118pf+rq</latexit> Divide-ad-coquer: quiz 4 Media-of-medias selectio algorithm recurrece Cosider the followig recurrece 0 1 C() = C( /5 )+C( 3 /10 ) >1 Is C() mootoe o-decreasig? A. Yes, obviously. B. Yes, but proof is tedious. C. Yes, but proof is hard. D. No. Aalysis of selectio algorithm recurrece. T() = max # compares o ay array of elemets. T() is mootoe o-decreasig, but C() is ot! T () Claim. T() 44. Pf. [ by strog iductio ] 6 <50 max{ T ( 1), T( /5 )+T( 3 /10 ) ) } 50 Base case: T() 6 for < 50 (mergesort). Iductive hypothesis: assume true for 1,,, 1. Iductio step: for 50, we have either T() T( 1) 44 or T() T( / 5 ) + T( 3 / 10 ) + 11/5 C(19) = 165 C(0) = 134. iductive hypothesis 44 ( / 5 ) + 44 ( 3 / 10 ) + 11/5 44 ( / 5) ( / 4) + 11/5 for 50, 3 / 10 / 4 59 = Divide-ad-coquer: quiz 5 Liear-time selectio retrospective Suppose that we divide elemets ito / r groups of r elemets each, ad use the media-of-medias of these / r groups as the pivot. For which r is the worst-case ruig time of select O()? A. r = 3 T() = T( / 3) + T( / 6) + Θ() T() = Θ( log ) B. r = 7 T() = T( / 7) + T( 4 / 14) + Θ() T() = Θ() C. Both A ad B. D. Neither A or B. 61 Propositio. [Blum Floyd Pratt Rivest Tarja 1973] There exists a compare-based selectio algorithm whose worst-case ruig time is O(). Time Bouds for Selectio* MANUEL BLUM, ROBERT W. FLOYD, VAUGHAN PRATT, RONALD L. RIVEST, AND ROBERT E. TARJAN Departmet of Computer Sciece, Staford Uiversity, Staford, Califoria Received November 14, 197 The umber of comparisos required to select the i-th smallest of umbers is show to be at most a liear fuctio of by aalysis of a ew selectio algorithm--pick. Specifically, o more tha comparisos are ever required. This boud is improved for extreme values of i, ad a ew lower boud o the requisite umber of comparisos is also proved. Theory. Optimized versio of BFPRT: compares. Upper boud: [Dor Zwick 1995].95 compares. Lower boud: [Dor Zwick 1999] ( + 80 ) compares. Practice. Costats too large to be useful. 6

16 Closest pair of poits 5. DIVIDE AND CONQUER Closest pair problem. Give poits i the plae, fid a pair of poits with the smallest Euclidea distace betwee them. mergesort coutig iversios radomized quicksort media ad selectio closest pair of poits Fudametal geometric primitive. Graphics, computer visio, geographic iformatio systems, molecular modelig, air traffic cotrol. Special case of earest eighbor, Euclidea MST, Vorooi. fast closest pair ispired fast algorithms for these problems SECTION Closest pair of poits Closest pair of poits: first attempt Closest pair problem. Give poits i the plae, fid a pair of poits with the smallest Euclidea distace betwee them. Brute force. Check all pairs with Θ( ) distace calculatios. Sortig solutio. Sort by x-coordiate ad cosider earby poits. Sort by y-coordiate ad cosider earby poits. 1D versio. Easy O( log ) algorithm if poits are o a lie. No-degeeracy assumptio. No two poits have the same x-coordiate

17 Closest pair of poits: first attempt Closest pair of poits: secod attempt Sortig solutio. Sort by x-coordiate ad cosider earby poits. Sort by y-coordiate ad cosider earby poits. Divide. Subdivide regio ito 4 quadrats Closest pair of poits: secod attempt Closest pair of poits: divide-ad-coquer algorithm Divide. Subdivide regio ito 4 quadrats. Obstacle. Impossible to esure / 4 poits i each piece. Divide: draw vertical lie L so that / poits o each side. Coquer: fid closest pair i each side recursively. Combie: fid closest pair with oe poit i each side. Retur best of 3 solutios. seems like Θ( ) L

18 How to fid closest pair with oe poit i each side? How to fid closest pair with oe poit i each side? Fid closest pair with oe poit i each side, assumig that distace < δ. Observatio: suffices to cosider oly those poits withi δ of lie L. Fid closest pair with oe poit i each side, assumig that distace < δ. Observatio: suffices to cosider oly those poits withi δ of lie L. Sort poits i δ-strip by their y-coordiate. Check distaces of oly those poits withi 7 positios i sorted list! why? L L δ = mi(1, 1) 1 3 δ = mi(1, 1) 1 δ 71 δ 7 How to fid closest pair with oe poit i each side? Closest pair of poits: divide-ad-coquer algorithm Def. Let s i be the poit i the δ-strip, with the i th smallest y-coordiate. Claim. If j i > 7, the the distace betwee s i ad s j is at least δ. Pf. Cosider the δ-by-δ rectagle R i strip whose mi y-coordiate is y-coordiate of s i. Distace betwee s i ad ay poit s j above R is δ. Subdivide R ito 8 squares. At most 1 poit per square. diameter is / < At most 7 other poits ca be i R. δ R si L s j ½δ ½δ CLOSEST-PAIR(p 1, p,, p ) Compute vertical lie L such that half the poits are o each side of the lie. δ 1 CLOSEST-PAIR(poits i left half). δ CLOSEST-PAIR(poits i right half). δ mi { δ 1, δ }. Delete all poits further tha δ from lie L. Sort remaiig poits by y-coordiate. Sca poits i y-order ad compare distace betwee each poit ad ext 7 eighbors. If ay of these distaces is less tha δ, update δ. O() T( / ) T( / ) O() O( log ) O() costat ca be improved with more refied geometric packig argumet RETURN δ. δ 73 74

19 Divide-ad-coquer: quiz 6 Refied versio of closest-pair algorithm What is the solutio to the followig recurrece? Q. How to improve to O( log )? A. Do t sort poits i strip from scratch each time. Each recursive call returs two lists: all poits sorted by x-coordiate, (1) =1 ad all poits sorted by y-coordiate. >1 Sort by mergig two pre-sorted lists. T () = T ( / ) + T ( / ) + ( log ) <latexit sha1_base64="dpqsxs9emydq5iq+l5by9kuo1i=">aaacicbvfnixnbeo0zv9b4lv0phrwuzpueic4swq6elqvbpa6quavpifr0apjme7qh7h5jghlyjf79i/4c/409vkwixv6vfdvrz7sqgrrouhpen66fefuvb37rqcphz1+0t4/+gp1atioujbaxkbmohqkr044izefqzaei/sqw+1fvenjrvaddywcrmyuywzz1kt9e9hvptiffk1xjltffs+7atebhc7rsw7cg1dahs5cbskdq+vz40nyaaxjqh+meejzh10qm6m1afxmckhz4x7qwws6gfrkkgsj1fbgajwuuklohas3t9ytsiqatpbpnj+te6ybfedeiqjs4+8ebwpe5qgcl8zacrwvlqmycyjl9muwfgvgr9gmxx4qlqnnqvvtv/dsm1pi/g6zvg7w7l8vfcutxeapz8yzm9ttrsb/p41ll50klvbf6vdxa6osloa01i+cqtdivx6wlgrflbgcyyd/6dgy7r3gxyjuqrake11pcyqvbompqk8bbn9sfo6p+u3785w37kq55x55tl6qlojmtkj8k5greepatog4/bpzajv4c/wp/xqwhq1dwlgxh++gt4httm</latexit> A. T() = Θ(). B. T() = Θ( log ). C. T() = Θ( log ). D. Theorem. [Shamos 1975] The divide-ad-coquer algorithm for fidig a closest pair of poits i the plae ca be implemeted i O( log ) time. Pf. T() = Θ(). (1) =1 T () = T ( / ) + T ( / ) + () >1 <latexit sha1_base64="3pqz3or04schqniwe5a09tyf+wa=">aaac03icbvfnb9naef7fjtwlzyjlxepkbfsaleifkvajc4ci5s0lbjwtn6mk1xxat3xsuyuscu/bh+ef+gtetkjgfot+/nzjupojfccd44/l79+4/elj/qpx4ydnz9shhxcmkzthmc9kpq9izlakhwmrrmsrxcnly4mx8fwxsr+8qw1epkzlwousrksiedmomra/j3qqh58hbancs5uyv0vs7rar0t0ljuim3qc0ubqkigsplcsmjwaolk6b/imkckddkhozzrru8qlqxeme0mfboobk5chko1xwtmo81i7hpzupfku1a4aatjtbp6gddkhyga5p4x64b3swcalfjxlkhkzcypcrixtvcjbsvcym74nzvjxehfujrrwr91da8dm4pelzvkykln/ltrstsyvrq7zjtzhdwkvj/qswyvlucpuxfhw/nuokctad6kmwexq5lsshgnfczqp8wttj1v1xw6xuspfkrcfkrwbizbrlrlq1l1xxd7zrtgfnl/0a+/vesmz5pz7pox5bxpkpcckih5ss7jmhcv7b33ptd/8l/7v/wf96m+l5t84jshp/rl+pwnq=</latexit> Divide-ad-coquer: quiz 7 Computatioal complexity of closest-pair problem What is the complexity of the D closest pair problem? Theorem. [Be-Or 1983, Yao 1989] I quadratic decisio tree model, ay algorithm for closest pair (eve i 1D) requires Ω( log ) quadratic tests. A. Θ(). B. Θ( log* ). C. Θ( log log ). D. Θ( log ). E. Not eve Tarja kows. (x1 - x) + (y1 - y) Theorem. [Rabi 1976] There exists a algorithm to fid the closest pair of poits i the plae whose expected ruig time is O(). Volume 8, umber 1 IhFCRMATION PROCESSING LE,TTERS A NOTE ON RABIN S NEAREST-NEIGHBOR ALGORITHM * Steve FORTUNE ad Joh HOPCROFT Jauary 1979 ot subject to Ω( log ) lower boud because it uses the floor fuctio Departmet of Computer Sciece, Corell Uiversity,Ithaca, NY, U.S.A. Received 0 July 1978, revised versio received 1 August 1978 Probabiktic algorithms, earest eighbor, hashig itroductio Oe otio that has received some attetio recetly is that of a probabilistic algorithm. A algo- tio to the distace betwee earest eighbors i the whole set. Usig this approximatio the distace betwee the earest eighbor i the whole set ca be foud i expected liear time. The algorithm s use of

20 Digressio: computatioal geometry Covex hull Igeious divide-ad-coquer algorithms for core geometric problems. problem brute clever closest pair O( ) O( log ) farthest pair O( ) O( log ) covex hull O( ) O( log ) Delauay/Vorooi O( 4 ) O( log ) Euclidea MST O( ) O( log ) ruig time to solve a D problem with poits Note. 3D ad higher dimesios test limits of our igeuity. The covex hull of a set of poits is the smallest perimeter fece eclosig the poits. Equivalet defiitios. Smallest area covex polygo eclosig the poits. Itersectio of all covex set cotaiig all the poits Farthest pair Delauay triagulatio Give poits i the plae, fid a pair of poits with the largest Euclidea distace betwee them. Fact. Poits i farthest pair are extreme poits o covex hull. 81 The Delauay triagulatio is a triagulatio of poits i the plae such that o poit is iside the circumcircle of ay triagle. poit iside circumcircle of 3 poits Some useful properties. No edges cross. Delauay triagulatio of 19 poits Amog all triagulatios, it maximizes the miimum agle. Cotais a edge betwee each poit ad its earest eighbor. o poit i the set is iside the circumcircle 8

21 Euclidea MST Computatioal geometry applicatios Give poits i the plae, fid MST coectig them. [distaces betwee poit pairs are Euclidea distaces] Fact. Euclidea MST is subgraph of Delauay triagulatio. Implicatio. Ca compute Euclidea MST i O( log ) time. Compute Delauay triagulatio. Compute MST of Delauay triagulatio. it s plaar ( 3 edges) 83 Applicatios. Robotics. VLSI desig. Data miig. Medical imagig. Computer visio. Scietific computig. Fiite-elemet meshig. Astroomical simulatio. Models of physical world. Geographic iformatio systems. Computer graphics (movies, games, virtual reality). airflow aroud a aircraft wig 84

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions randomized quicksort median and selection closest pair of points Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points randomized quicksort median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia) 1 CS 332: Algorithms Liear-Time Sortig. Order statistics. Slide credit: David Luebke (Virgiia) Quicksort: Partitio I Words Partitio(A, p, r): Select a elemet to act as the pivot (which?) Grow two regios,

More information

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials. Divide-ad-coquer algorithms Divide & Coquer Strategy: Divide the problem ito smaller subproblems of the same type of problem Solve the subproblems recursively Combie the aswers to solve the origial problem

More information

CS / MCS 401 Homework 3 grader solutions

CS / MCS 401 Homework 3 grader solutions CS / MCS 401 Homework 3 grader solutios assigmet due July 6, 016 writte by Jāis Lazovskis maximum poits: 33 Some questios from CLRS. Questios marked with a asterisk were ot graded. 1 Use the defiitio of

More information

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU. Sortig Algorithms Algorithms Kyuseo Shim SoEECS, SNU. Desigig Algorithms Icremetal approaches Divide-ad-Coquer approaches Dyamic programmig approaches Greedy approaches Radomized approaches You are ot

More information

Analysis of Algorithms -Quicksort-

Analysis of Algorithms -Quicksort- Aalysis of Algorithms -- Adreas Ermedahl MRTC (Mälardales Real-Time Research Ceter) adreas.ermedahl@mdh.se Autum 2004 Proposed by C.A.R. Hoare i 962 Worst- case ruig time: Θ( 2 ) Expected ruig time: Θ(

More information

Data Structures Lecture 9

Data Structures Lecture 9 Fall 2017 Fag Yu Software Security Lab. Dept. Maagemet Iformatio Systems, Natioal Chegchi Uiversity Data Structures Lecture 9 Midterm o Dec. 7 (9:10-12:00am, 106) Lec 1-9, TextBook Ch1-8, 11,12 How to

More information

Model of Computation and Runtime Analysis

Model of Computation and Runtime Analysis Model of Computatio ad Rutime Aalysis Model of Computatio Model of Computatio Specifies Set of operatios Cost of operatios (ot ecessarily time) Examples Turig Machie Radom Access Machie (RAM) PRAM Map

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms CSE 53 Lecture 9 Media ad Order Statistics Juzhou Huag, Ph.D. Departmet of Computer Sciece ad Egieerig Dept. CSE, UT Arligto CSE53 Desig ad Aalysis of Algorithms Medias ad

More information

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2 Geeral remarks Week 2 1 Divide ad First we cosider a importat tool for the aalysis of algorithms: Big-Oh. The we itroduce a importat algorithmic paradigm:. We coclude by presetig ad aalysig two examples.

More information

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2 This Lecture Divide-ad-coquer techique for algorithm desig. Example the merge sort. Writig ad solvig recurreces Divide ad Coquer Divide-ad-coquer method for algorithm desig: Divide: If the iput size is

More information

Data Structures and Algorithm. Xiaoqing Zheng

Data Structures and Algorithm. Xiaoqing Zheng Data Structures ad Algorithm Xiaoqig Zheg zhegxq@fudaeduc What are algorithms? A sequece of computatioal steps that trasform the iput ito the output Sortig problem: Iput: A sequece of umbers

More information

Model of Computation and Runtime Analysis

Model of Computation and Runtime Analysis Model of Computatio ad Rutime Aalysis Model of Computatio Model of Computatio Specifies Set of operatios Cost of operatios (ot ecessarily time) Examples Turig Machie Radom Access Machie (RAM) PRAM Map

More information

Merge and Quick Sort

Merge and Quick Sort Merge ad Quick Sort Merge Sort Merge Sort Tree Implemetatio Quick Sort Pivot Item Radomized Quick Sort Adapted from: Goodrich ad Tamassia, Data Structures ad Algorithms i Java, Joh Wiley & So (1998). Ruig

More information

Analysis of Algorithms. Introduction. Contents

Analysis of Algorithms. Introduction. Contents Itroductio The focus of this module is mathematical aspects of algorithms. Our mai focus is aalysis of algorithms, which meas evaluatig efficiecy of algorithms by aalytical ad mathematical methods. We

More information

Divide-Conquer-Glue Algorithms

Divide-Conquer-Glue Algorithms Divide-Conquer-Glue Algorithms Mergesort and Counting Inversions Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 10 Divide-and-conquer. Divide up problem into several subproblems. Solve each subproblem recursively.

More information

2. ALGORITHM ANALYSIS

2. ALGORITHM ANALYSIS 2. ALGORITHM ANALYSIS computatioal tractability survey of commo ruig times 2. ALGORITHM ANALYSIS computatioal tractability survey of commo ruig times Lecture slides by Kevi Waye Copyright 2005 Pearso-Addiso

More information

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides CS583 Lecture 02 Jaa Kosecka some materials here are based o E. Demaie, D. Luebke slides Previously Sample algorithms Exact ruig time, pseudo-code Approximate ruig time Worst case aalysis Best case aalysis

More information

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions CSE 09/09 Topics i ig Data Aalytics Sprig 2017; Homework 1 Solutios Note: Solutios to problems,, ad 6 are due to Marius Nicolae. 1. Cosider the followig algorithm: for i := 1 to α log e do Pick a radom

More information

) n. ALG 1.3 Deterministic Selection and Sorting: Problem P size n. Examples: 1st lecture's mult M(n) = 3 M ( È

) n. ALG 1.3 Deterministic Selection and Sorting: Problem P size n. Examples: 1st lecture's mult M(n) = 3 M ( È Algorithms Professor Joh Reif ALG 1.3 Determiistic Selectio ad Sortig: (a) Selectio Algorithms ad Lower Bouds (b) Sortig Algorithms ad Lower Bouds Problem P size fi divide ito subproblems size 1,..., k

More information

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply: Departmet of Iformatics Prof. Dr. Michael Böhle Bizmühlestrasse 14 8050 Zurich Phoe: +41 44 635 4333 Email: boehle@ifi.uzh.ch AlgoDat Midterm1 Sprig 016 08.04.016 Name: Matriculatio umber: Advice You have

More information

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc) Classificatio of problem & problem solvig strategies classificatio of time complexities (liear, arithmic etc) Problem subdivisio Divide ad Coquer strategy. Asymptotic otatios, lower boud ad upper boud:

More information

Test One (Answer Key)

Test One (Answer Key) CS395/Ma395 (Sprig 2005) Test Oe Name: Page 1 Test Oe (Aswer Key) CS395/Ma395: Aalysis of Algorithms This is a closed book, closed otes, 70 miute examiatio. It is worth 100 poits. There are twelve (12)

More information

Design and Analysis of ALGORITHM (Topic 2)

Design and Analysis of ALGORITHM (Topic 2) DR. Gatot F. Hertoo, MSc. Desig ad Aalysis of ALGORITHM (Topic 2) Algorithms + Data Structures = Programs Lessos Leared 1 Our Machie Model: Assumptios Geeric Radom Access Machie (RAM) Executes operatios

More information

CS 332: Algorithms. Quicksort

CS 332: Algorithms. Quicksort CS 33: Aorithms Quicsort David Luebe //03 Homewor Assiged today, due ext Wedesday Will be o web page shortly after class Go over ow David Luebe //03 Review: Quicsort Sorts i place Sorts O( ) i the average

More information

A Probabilistic Analysis of Quicksort

A Probabilistic Analysis of Quicksort A Probabilistic Aalysis of Quicsort You are assumed to be familiar with Quicsort. I each iteratio this sortig algorithm chooses a pivot ad the, by performig comparisios with the pivot, splits the remaider

More information

Advanced Course of Algorithm Design and Analysis

Advanced Course of Algorithm Design and Analysis Differet complexity measures Advaced Course of Algorithm Desig ad Aalysis Asymptotic complexity Big-Oh otatio Properties of O otatio Aalysis of simple algorithms A algorithm may may have differet executio

More information

COMP285 Midterm Exam Department of Mathematics

COMP285 Midterm Exam Department of Mathematics COMP85 Midterm Exam Departmet of Mathematics Fall 010/011 - November 8, 010 Name: Studet Number: Please fiish withi 90 miutes. All poits above 100 are cosidered as bous poit. You ca reach maximal 1 poits.

More information

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary Recursive Algorithm for Geeratig Partitios of a Iteger Sug-Hyuk Cha Computer Sciece Departmet, Pace Uiversity 1 Pace Plaza, New York, NY 10038 USA scha@pace.edu Abstract. This article first reviews the

More information

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016 CS161: Algorithm Desig ad Aalysis Hadout #10 Staford Uiversity Wedesday, 10 February 2016 Lecture #11: Wedesday, 10 February 2016 Topics: Example midterm problems ad solutios from a log time ago Sprig

More information

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2 Shiyao Wag CS:3330 (Prof. Pemmaraju ): Assigmet #1 Solutios Problem 1 (a) Cosider iput with me m 1, m,..., m ad wome w 1, w,..., w with the followig prefereces: All me have the same prefereces for wome:

More information

Recurrence Relations

Recurrence Relations Recurrece Relatios Aalysis of recursive algorithms, such as: it factorial (it ) { if (==0) retur ; else retur ( * factorial(-)); } Let t be the umber of multiplicatios eeded to calculate factorial(). The

More information

4.3 Growth Rates of Solutions to Recurrences

4.3 Growth Rates of Solutions to Recurrences 4.3. GROWTH RATES OF SOLUTIONS TO RECURRENCES 81 4.3 Growth Rates of Solutios to Recurreces 4.3.1 Divide ad Coquer Algorithms Oe of the most basic ad powerful algorithmic techiques is divide ad coquer.

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms Probabilistic aalysis ad Radomized algorithms Referece: CLRS Chapter 5 Topics: Hirig problem Idicatio radom variables Radomized algorithms Huo Hogwei 1 The hirig problem

More information

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability.

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability. CSE 0 Homework 1 Matthias Spriger, A9950078 1 Problem 1 Notatio a b meas that a is matched to b. a < b c meas that b likes c more tha a. Equality idicates a tie. Strog istability Yes, there does always

More information

Chapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each

More information

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN CSI 5163 (95.5703) ALGORITHM ANALYSIS AND DESIGN (3 cr.) (T) Topics of curret iterest i the desig ad aalysis of computer algorithms for graphtheoretical

More information

1 Hash tables. 1.1 Implementation

1 Hash tables. 1.1 Implementation Lecture 8 Hash Tables, Uiversal Hash Fuctios, Balls ad Bis Scribes: Luke Johsto, Moses Charikar, G. Valiat Date: Oct 18, 2017 Adapted From Virgiia Williams lecture otes 1 Hash tables A hash table is a

More information

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone: Departmet of Iformatics Prof. Dr. Michael Böhle Bizmühlestrasse 14 8050 Zurich Phoe: +41 44 635 4333 Email: boehle@ifi.uzh.ch Iformatik II Midterm1 Sprig 018 3.03.018 Advice You have 90 miutes to complete

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures ad Algorithms Autum 2017-2018 Outlie 1 Sortig Algorithms (cotd) Outlie Sortig Algorithms (cotd) 1 Sortig Algorithms (cotd) Heapsort Sortig Algorithms (cotd) Have see that we ca build a

More information

Approximate Sorting. Institute for Theoretical Computer Science, ETH Zürich, CH-8092 Zürich

Approximate Sorting. Institute for Theoretical Computer Science, ETH Zürich, CH-8092 Zürich Approximate Sortig Joachim Giese, Eva Schuberth, ad Miloš Stojaković Istitute for Theoretical Computer Sciece, ETH Zürich, CH-809 Zürich Abstract. We show that ay radomized algorithm to approximate ay

More information

Examples: data compression, path-finding, game-playing, scheduling, bin packing

Examples: data compression, path-finding, game-playing, scheduling, bin packing Algorithms - Basic Cocepts Algorithms so what is a algorithm, ayway? The dictioary defiitio: A algorithm is a well-defied computatioal procedure that takes iput ad produces output. This class will deal

More information

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES Peter M. Maurer Why Hashig is θ(). As i biary search, hashig assumes that keys are stored i a array which is idexed by a iteger. However, hashig attempts to bypass

More information

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ.

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ. 2 5. Weighted umber of late jobs 5.1. Release dates ad due dates: maximimizig the weight of o-time jobs Oce we add release dates, miimizig the umber of late jobs becomes a sigificatly harder problem. For

More information

Algorithms and Data Structures Lecture IV

Algorithms and Data Structures Lecture IV Algorithms ad Data Structures Lecture IV Simoas Šalteis Aalborg Uiversity simas@cs.auc.dk September 5, 00 1 This Lecture Aalyzig the ruig time of recursive algorithms (such as divide-ad-coquer) Writig

More information

Lecture 14: Randomized Computation (cont.)

Lecture 14: Randomized Computation (cont.) CSE 200 Computability ad Complexity Wedesday, May 15, 2013 Lecture 14: Radomized Computatio (cot.) Istructor: Professor Shachar Lovett Scribe: Dogcai She 1 Radmized Algorithm Examples 1.1 The k-th Elemet

More information

An Introduction to Randomized Algorithms

An Introduction to Randomized Algorithms A Itroductio to Radomized Algorithms The focus of this lecture is to study a radomized algorithm for quick sort, aalyze it usig probabilistic recurrece relatios, ad also provide more geeral tools for aalysis

More information

CSE 417, Winter Greedy Algorithms

CSE 417, Winter Greedy Algorithms CSE 417, Witer 2012 Greedy Algorithms Be Birbaum Widad Machmouchi Slides adapted from Larry Ruzzo, Steve Taimoto, ad Kevi Waye 1 Chapter 4 Greedy Algorithms Slides by Kevi Waye. Copyright 2005 Pearso-Addiso

More information

Divide-and-Conquer. Consequence. Brute force: n 2. Divide-and-conquer: n log n. Divide et impera. Veni, vidi, vici.

Divide-and-Conquer. Consequence. Brute force: n 2. Divide-and-conquer: n log n. Divide et impera. Veni, vidi, vici. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common usage. Break up problem of

More information

DATA STRUCTURES I, II, III, AND IV

DATA STRUCTURES I, II, III, AND IV Data structures DATA STRUCTURES I, II, III, AND IV I. Amortized Aalysis II. Biary ad Biomial Heaps III. Fiboacci Heaps IV. Uio Fid Static problems. Give a iput, produce a output. Ex. Sortig, FFT, edit

More information

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1 Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Skip Lists S 3 15 15 23 10 15 23 36 Skip Lists 1 What is a Skip List A skip list for

More information

CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo Coutig Methods CSE 191, Class Note 05: Coutig Methods Computer Sci & Eg Dept SUNY Buffalo c Xi He (Uiversity at Buffalo CSE 191 Discrete Structures 1 / 48 Need for Coutig The problem of coutig the umber

More information

Fundamenta Informaticae XXI (2001) IOS Press

Fundamenta Informaticae XXI (2001) IOS Press Fudameta Iformaticae XXI (2001) 1001 1006 1001 IOS Press Approximate Sortig Joachim Giese Max Plak Istitute for Computer Sciece Saarbrücke, Germay Eva Schuberth Istitute for Theoretical Computer Sciece

More information

CSED233: Data Structures (2018F) Lecture13: Sorting and Selection

CSED233: Data Structures (2018F) Lecture13: Sorting and Selection (018F) Lecture13: Sortig ad Selectio Daiji Kim CSE, POSECH dkim@postech.ac.kr Divide-ad-Coquer Divide-ad coquer a geeral algorithm desig paradigm: Divide: divide the iput data S i two djoit susets S 1

More information

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources Algorithm Aalysis Algorithms that are equally correct ca vary i their utilizatio of computatioal resources time ad memory a slow program it is likely ot to be used a program that demads too much memory

More information

Problem Set 2 Solutions

Problem Set 2 Solutions CS271 Radomess & Computatio, Sprig 2018 Problem Set 2 Solutios Poit totals are i the margi; the maximum total umber of poits was 52. 1. Probabilistic method for domiatig sets 6pts Pick a radom subset S

More information

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014 Iteger Divisio Algorithm ad Cogruece Iteger Trial divisio,,, ad with itegers mod Iverses mod Multiplicatio ad GCD Iteger Christopher Koch 1 1 Departmet of Computer Sciece ad Egieerig CSE489/589 Algorithms

More information

Disjoint set (Union-Find)

Disjoint set (Union-Find) CS124 Lecture 7 Fall 2018 Disjoit set (Uio-Fid) For Kruskal s algorithm for the miimum spaig tree problem, we foud that we eeded a data structure for maitaiig a collectio of disjoit sets. That is, we eed

More information

Lecture 7: October 18, 2017

Lecture 7: October 18, 2017 Iformatio ad Codig Theory Autum 207 Lecturer: Madhur Tulsiai Lecture 7: October 8, 207 Biary hypothesis testig I this lecture, we apply the tools developed i the past few lectures to uderstad the problem

More information

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006 MATH 34 Summer 006 Elemetary Number Theory Solutios to Assigmet Due: Thursday July 7, 006 Departmet of Mathematical ad Statistical Scieces Uiversity of Alberta Questio [p 74 #6] Show that o iteger of the

More information

TEACHER CERTIFICATION STUDY GUIDE

TEACHER CERTIFICATION STUDY GUIDE COMPETENCY 1. ALGEBRA SKILL 1.1 1.1a. ALGEBRAIC STRUCTURES Kow why the real ad complex umbers are each a field, ad that particular rigs are ot fields (e.g., itegers, polyomial rigs, matrix rigs) Algebra

More information

CSE 5311 Notes 1: Mathematical Preliminaries

CSE 5311 Notes 1: Mathematical Preliminaries Chapter 1 - Algorithms Computig CSE 5311 Notes 1: Mathematical Prelimiaries Last updated 1/20/18 12:56 PM) Relatioship betwee complexity classes, eg log,, log, 2, 2, etc Chapter 2 - Gettig Started Loop

More information

Algorithms Design & Analysis. Divide & Conquer

Algorithms Design & Analysis. Divide & Conquer Algorithms Desig & Aalysis Divide & Coquer Recap Direct-accessible table Hash tables Hash fuctios Uiversal hashig Perfect Hashig Ope addressig 2 Today s topics The divide-ad-coquer desig paradigm Revised

More information

Complex Numbers Solutions

Complex Numbers Solutions Complex Numbers Solutios Joseph Zoller February 7, 06 Solutios. (009 AIME I Problem ) There is a complex umber with imagiary part 64 ad a positive iteger such that Fid. [Solutio: 697] 4i + + 4i. 4i 4i

More information

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

Mathematical Foundation. CSE 6331 Algorithms Steve Lai Mathematical Foudatio CSE 6331 Algorithms Steve Lai Complexity of Algorithms Aalysis of algorithm: to predict the ruig time required by a algorithm. Elemetary operatios: arithmetic & boolea operatios:

More information

Induction: Solutions

Induction: Solutions Writig Proofs Misha Lavrov Iductio: Solutios Wester PA ARML Practice March 6, 206. Prove that a 2 2 chessboard with ay oe square removed ca always be covered by shaped tiles. Solutio : We iduct o. For

More information

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Itroductio to Algorithms 6.046J/8.40J LECTURE 3 Divide ad coquer Biary search Powerig a umber Fiboacci umbers Matrix multiplicatio Strasse s algorithm VLSI tree layout Prof. Charles E. Leiserso The divide-ad-coquer

More information

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016 COMPSCI 330: Desig ad Aalysis of Algorithms 1/19/2016 ad 1/21/2016 Lecturer: Debmalya Paigrahi Divide ad Coquer Scribe: Tiaqi Sog 1 Overview I this lecture, a importat algorithm desig techique called divide-ad-coquer

More information

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis Recursive Algorithms Recurreces Computer Sciece & Egieerig 35: Discrete Mathematics Christopher M Bourke cbourke@cseuledu A recursive algorithm is oe i which objects are defied i terms of other objects

More information

HOMEWORK 2 SOLUTIONS

HOMEWORK 2 SOLUTIONS HOMEWORK SOLUTIONS CSE 55 RANDOMIZED AND APPROXIMATION ALGORITHMS 1. Questio 1. a) The larger the value of k is, the smaller the expected umber of days util we get all the coupos we eed. I fact if = k

More information

CS 5150/6150: Assignment 1 Due: Sep 23, 2010

CS 5150/6150: Assignment 1 Due: Sep 23, 2010 CS 5150/6150: Assigmet 1 Due: Sep 23, 2010 Wei Liu September 24, 2010 Q1: (1) Usig master theorem: a = 7, b = 4, f() = O(). Because f() = log b a ε holds whe ε = log b a = log 4 7, we ca apply the first

More information

IP Reference guide for integer programming formulations.

IP Reference guide for integer programming formulations. IP Referece guide for iteger programmig formulatios. by James B. Orli for 15.053 ad 15.058 This documet is iteded as a compact (or relatively compact) guide to the formulatio of iteger programs. For more

More information

Sums, products and sequences

Sums, products and sequences Sums, products ad sequeces How to write log sums, e.g., 1+2+ (-1)+ cocisely? i=1 Sum otatio ( sum from 1 to ): i 3 = 1 + 2 + + If =3, i=1 i = 1+2+3=6. The ame ii does ot matter. Could use aother letter

More information

The Boolean Ring of Intervals

The Boolean Ring of Intervals MATH 532 Lebesgue Measure Dr. Neal, WKU We ow shall apply the results obtaied about outer measure to the legth measure o the real lie. Throughout, our space X will be the set of real umbers R. Whe ecessary,

More information

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 12

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 12 Machie Learig Theory Tübige Uiversity, WS 06/07 Lecture Tolstikhi Ilya Abstract I this lecture we derive risk bouds for kerel methods. We will start by showig that Soft Margi kerel SVM correspods to miimizig

More information

Solutions to Homework 7

Solutions to Homework 7 Solutios to Homework 7 Due Wedesday, August 4, 004. Chapter 4.1) 3, 4, 9, 0, 7, 30. Chapter 4.) 4, 9, 10, 11, 1. Chapter 4.1. Solutio to problem 3. The sum has the form a 1 a + a 3 with a k = 1/k. Sice

More information

6.003 Homework #3 Solutions

6.003 Homework #3 Solutions 6.00 Homework # Solutios Problems. Complex umbers a. Evaluate the real ad imagiary parts of j j. π/ Real part = Imagiary part = 0 e Euler s formula says that j = e jπ/, so jπ/ j π/ j j = e = e. Thus the

More information

A New Solution Method for the Finite-Horizon Discrete-Time EOQ Problem

A New Solution Method for the Finite-Horizon Discrete-Time EOQ Problem This is the Pre-Published Versio. A New Solutio Method for the Fiite-Horizo Discrete-Time EOQ Problem Chug-Lu Li Departmet of Logistics The Hog Kog Polytechic Uiversity Hug Hom, Kowloo, Hog Kog Phoe: +852-2766-7410

More information

The multiplicative structure of finite field and a construction of LRC

The multiplicative structure of finite field and a construction of LRC IERG6120 Codig for Distributed Storage Systems Lecture 8-06/10/2016 The multiplicative structure of fiite field ad a costructio of LRC Lecturer: Keeth Shum Scribe: Zhouyi Hu Notatios: We use the otatio

More information

Seunghee Ye Ma 8: Week 5 Oct 28

Seunghee Ye Ma 8: Week 5 Oct 28 Week 5 Summary I Sectio, we go over the Mea Value Theorem ad its applicatios. I Sectio 2, we will recap what we have covered so far this term. Topics Page Mea Value Theorem. Applicatios of the Mea Value

More information

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5 CIS 11 Data Structures ad Algorithms with Java Sprig 019 Code Sippets ad Recurreces Moday, February 4/Tuesday, February 5 Learig Goals Practice provig asymptotic bouds with code sippets Practice solvig

More information

Fourier Analysis, Stein and Shakarchi Chapter 8 Dirichlet s Theorem

Fourier Analysis, Stein and Shakarchi Chapter 8 Dirichlet s Theorem Fourier Aalysis, Stei ad Shakarchi Chapter 8 Dirichlet s Theorem 208.05.05 Abstract Durig the course Aalysis II i NTU 208 Sprig, this solutio file is latexed by the teachig assistat Yug-Hsiag Huag with

More information

Davenport-Schinzel Sequences and their Geometric Applications

Davenport-Schinzel Sequences and their Geometric Applications Advaced Computatioal Geometry Sprig 2004 Daveport-Schizel Sequeces ad their Geometric Applicatios Prof. Joseph Mitchell Scribe: Mohit Gupta 1 Overview I this lecture, we itroduce the cocept of Daveport-Schizel

More information

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro COMP26120: More o the Complexity of Recursive Programs (2018/19) Lucas Cordeiro lucas.cordeiro@machester.ac.uk Divide-ad-Coquer (Recurrece) Textbook: Algorithm Desig ad Applicatios, Goodrich, Michael T.

More information

Lecture 16: Monotone Formula Lower Bounds via Graph Entropy. 2 Monotone Formula Lower Bounds via Graph Entropy

Lecture 16: Monotone Formula Lower Bounds via Graph Entropy. 2 Monotone Formula Lower Bounds via Graph Entropy 15-859: Iformatio Theory ad Applicatios i TCS CMU: Sprig 2013 Lecture 16: Mootoe Formula Lower Bouds via Graph Etropy March 26, 2013 Lecturer: Mahdi Cheraghchi Scribe: Shashak Sigh 1 Recap Graph Etropy:

More information

Section 5.1 The Basics of Counting

Section 5.1 The Basics of Counting 1 Sectio 5.1 The Basics of Coutig Combiatorics, the study of arragemets of objects, is a importat part of discrete mathematics. I this chapter, we will lear basic techiques of coutig which has a lot of

More information

Advanced Analysis. Min Yan Department of Mathematics Hong Kong University of Science and Technology

Advanced Analysis. Min Yan Department of Mathematics Hong Kong University of Science and Technology Advaced Aalysis Mi Ya Departmet of Mathematics Hog Kog Uiversity of Sciece ad Techology September 3, 009 Cotets Limit ad Cotiuity 7 Limit of Sequece 8 Defiitio 8 Property 3 3 Ifiity ad Ifiitesimal 8 4

More information

Hand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced

Hand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced Had Out Aalysis of Algorithms September 8, 998 Bud Mishra c Mishra, February 9, 986 Itroductio I geeral, there ca be several algorithms to solve a problem; ad oe is faced with the problem of choosig a

More information

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University Algorithms Elemetary Sortig Dog Kyue Kim Hayag Uiversity dqkim@hayag.a.kr Cotets Sortig problem Elemetary sortig algorithms Isertio sort Merge sort Seletio sort Bubble sort Sortig problem Iput A sequee

More information

Hashing and Amortization

Hashing and Amortization Lecture Hashig ad Amortizatio Supplemetal readig i CLRS: Chapter ; Chapter 7 itro; Sectio 7.. Arrays ad Hashig Arrays are very useful. The items i a array are statically addressed, so that isertig, deletig,

More information

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018 CSE 353 Discrete Computatioal Structures Sprig 08 Sequeces, Mathematical Iductio, ad Recursio (Chapter 5, Epp) Note: some course slides adopted from publisher-provided material Overview May mathematical

More information

Fundamental Algorithms

Fundamental Algorithms Fudametal Algorithms Chapter 2b: Recurreces Michael Bader Witer 2014/15 Chapter 2b: Recurreces, Witer 2014/15 1 Recurreces Defiitio A recurrece is a (i-equality that defies (or characterizes a fuctio i

More information

Information-based Feature Selection

Information-based Feature Selection Iformatio-based Feature Selectio Farza Faria, Abbas Kazeroui, Afshi Babveyh Email: {faria,abbask,afshib}@staford.edu 1 Itroductio Feature selectio is a topic of great iterest i applicatios dealig with

More information

Analysis of the Expected Number of Bit Comparisons Required by Quickselect

Analysis of the Expected Number of Bit Comparisons Required by Quickselect Aalysis of the Expected Number of Bit Comparisos Required by Quickselect James Alle Fill Takéhiko Nakama Abstract Whe algorithms for sortig ad searchig are applied to keys that are represeted as bit strigs,

More information

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS DEMETRES CHRISTOFIDES Abstract. Cosider a ivertible matrix over some field. The Gauss-Jorda elimiatio reduces this matrix to the idetity

More information

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018)

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018) Radomized Algorithms I, Sprig 08, Departmet of Computer Sciece, Uiversity of Helsiki Homework : Solutios Discussed Jauary 5, 08). Exercise.: Cosider the followig balls-ad-bi game. We start with oe black

More information

Math 155 (Lecture 3)

Math 155 (Lecture 3) Math 55 (Lecture 3) September 8, I this lecture, we ll cosider the aswer to oe of the most basic coutig problems i combiatorics Questio How may ways are there to choose a -elemet subset of the set {,,,

More information

Average-Case Analysis of QuickSort

Average-Case Analysis of QuickSort Average-Case Aalysis of QuickSort Comp 363 Fall Semester 003 October 3, 003 The purpose of this documet is to itroduce the idea of usig recurrece relatios to do average-case aalysis. The average-case ruig

More information