Data Structures and Algorithm Analysis (CSC317) Randomized algorithms (part 2)

Similar documents
Data Structures and Algorithm Analysis (CSC317) Randomized algorithms

Online-routing on the butterfly network: probabilistic analysis

Homework 1 Solutions CSE 101 Summer 2017

Merging to ordered sequences. Efficient (Parallel) Sorting. Merging (cont.)

PHYS 172: Modern Mechanics. Summer Lecture 4 The Momentum Principle & Predicting Motion Read

C/CS/Phys C191 Shor s order (period) finding algorithm and factoring 11/12/14 Fall 2014 Lecture 22

The Substring Search Problem

1 Notes on Order Statistics

Analysis of Arithmetic. Analysis of Arithmetic. Analysis of Arithmetic Round-Off Errors. Analysis of Arithmetic. Analysis of Arithmetic

ME 3600 Control Systems Frequency Domain Analysis

Regularization. Stephen Scott and Vinod Variyam. Introduction. Outline. Machine. Learning. Problems. Measuring. Performance.

Physics 161 Fall 2011 Extra Credit 2 Investigating Black Holes - Solutions The Following is Worth 50 Points!!!

15.081J/6.251J Introduction to Mathematical Programming. Lecture 6: The Simplex Method II

6 Matrix Concentration Bounds

Edge Cover Time for Regular Graphs

Chem 453/544 Fall /08/03. Exam #1 Solutions

H5 Gas meter calibration

Math 301: The Erdős-Stone-Simonovitz Theorem and Extremal Numbers for Bipartite Graphs

Splay Trees Handout. Last time we discussed amortized analysis of data structures

556: MATHEMATICAL STATISTICS I

Lot-sizing for inventory systems with product recovery

Multiple Criteria Secretary Problem: A New Approach

Physics: Work & Energy Beyond Earth Guided Inquiry

NOTICE WARNING CONCERNING COPYRIGHT RESTRICTIONS: The copyright law of the United States (title 17, U.S. Code) governs the making of photocopies or

CSCE 478/878 Lecture 4: Experimental Design and Analysis. Stephen Scott. 3 Building a tree on the training set Introduction. Outline.

Analysis of Finite Word-Length Effects

Kepler s problem gravitational attraction

Problem Set #10 Math 471 Real Analysis Assignment: Chapter 8 #2, 3, 6, 8

Lab 10: Newton s Second Law in Rotation

3.012 Fund of Mat Sci: Bonding Lecture 5/6. Comic strip removed for copyright reasons.

k. s k=1 Part of the significance of the Riemann zeta-function stems from Theorem 9.2. If s > 1 then 1 p s

Errata for Edition 1 of Coding the Matrix, January 13, 2017

THE NUMBER OF TWO CONSECUTIVE SUCCESSES IN A HOPPE-PÓLYA URN

Chapter 3: Theory of Modular Arithmetic 38

Solution to HW 3, Ma 1a Fall 2016

BEST CONSTANTS FOR UNCENTERED MAXIMAL FUNCTIONS. Loukas Grafakos and Stephen Montgomery-Smith University of Missouri, Columbia

The second law of thermodynamics - II.

A path-integral approach to CMB

Nuclear and Particle Physics - Lecture 20 The shell model

A Bijective Approach to the Permutational Power of a Priority Queue

1 Similarity Analysis

13. Adiabatic Invariants and Action-Angle Variables Michael Fowler

Solutions to Problem Set 8

Web-based Supplementary Materials for. Controlling False Discoveries in Multidimensional Directional Decisions, with

Recognizable Infinite Triangular Array Languages

Q. Obtain the Hamiltonian for a one electron atom in the presence of an external magnetic field.

15 Solving the Laplace equation by Fourier method

1 Explicit Explore or Exploit (E 3 ) Algorithm

Basic propositional and. The fundamentals of deduction

Approximating the minimum independent dominating set in perturbed graphs

Sincere Voting and Information Aggregation with Voting Costs

Random Variables and Probability Distribution Random Variable

Berkeley Math Circle AIME Preparation March 5, 2013

Rydberg-Rydberg Interactions

Ch 13 Universal Gravitation

Assessing the Reliability of Rating Data

Stanford University CS259Q: Quantum Computing Handout 8 Luca Trevisan October 18, 2012

Classical Worm algorithms (WA)

3.1 Random variables

New problems in universal algebraic geometry illustrated by boolean equations

Markscheme May 2017 Calculus Higher level Paper 3

FE FORMULATIONS FOR PLASTICITY

Physics 221 Lecture 41 Nonlinear Absorption and Refraction

FW Laboratory Exercise. Survival Estimation from Banded/Tagged Animals. Year No. i Tagged

ASTR415: Problem Set #6

Momentum is conserved if no external force

Particle Systems. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Continuous Charge Distributions: Electric Field and Electric Flux

Module 18: Outline. Magnetic Dipoles Magnetic Torques

Transverse Wakefield in a Dielectric Tube with Frequency Dependent Dielectric Constant

Conventional Interrater Reliability definitions, formulae, and worked examples in SPSS and STATISTICA

Image Enhancement: Histogram-based methods

Physics Fall Mechanics, Thermodynamics, Waves, Fluids. Lecture 18: System of Particles II. Slide 18-1

Topic 4a Introduction to Root Finding & Bracketing Methods

Electric Field. y s +q. Point charge: Uniformly charged sphere: Dipole: for r>>s :! ! E = 1. q 1 r 2 ˆr. E sphere. at <0,r,0> at <0,0,r>

Electromagnetism Physics 15b

9.1 The multiplicative group of a finite field. Theorem 9.1. The multiplicative group F of a finite field is cyclic.

PHYS Summer Professor Caillault Homework Solutions. Chapter 5

Dorin Andrica Faculty of Mathematics and Computer Science, Babeş-Bolyai University, Cluj-Napoca, Romania

3.6 Applied Optimization

II. Non-paper: Zeta functions in scattering problems evaluated on the real wave number axis. Andreas Wirzba. Institut fur Kernphysik, TH Darmstadt

Dymore User s Manual Two- and three dimensional dynamic inflow models

An Estimate of Incomplete Mixed Character Sums 1 2. Mei-Chu Chang 3. Dedicated to Endre Szemerédi for his 70th birthday.

Lecture 8 - Gauss s Law

763620SS STATISTICAL PHYSICS Solutions 2 Autumn 2012

Topics in Brain Computer Interfaces CS295-7

Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort

Method for Approximating Irrational Numbers

Practice Integration Math 120 Calculus I Fall 2015

Notes on McCall s Model of Job Search. Timothy J. Kehoe March if job offer has been accepted. b if searching

LECTURE 15. Phase-amplitude variables. Non-linear transverse motion

On a quantity that is analogous to potential and a theorem that relates to it

1. Show that the volume of the solid shown can be represented by the polynomial 6x x.

Practice Integration Math 120 Calculus I D Joyce, Fall 2013

Quasi-Randomness and the Distribution of Copies of a Fixed Graph

Review Exercise Set 16

The Chromatic Villainy of Complete Multipartite Graphs

INTRODUCTION. 2. Vectors in Physics 1

COMP Parallel Computing SMM (3) OpenMP Case Study: The Barnes-Hut N-body Algorithm

Single Particle State AB AB

Transcription:

Data Stuctues and Algoithm Analysis (CSC317) Randomized algoithms (at 2)

Hiing oblem - eview c Cost to inteview (low i ) Cost to fie/hie (exensive ) n Total numbe candidates m Total numbe hied c h O(c i n + c h m) Deends on ode of candidates! Constant no matte ode of candidates

Randomized hiing oblem(n) 1. andomly emute the list of candidates 2. Hie-Assistant(n) Hie-Assistant(n) 1. best = 0 //least qualified candidate 2. fo i = 1 to n 3. inteview candidate i 4. if candidate i bette than best 5. best = i 6. hie candidate i

Randomized hiing oblem(n) Instead of wost case We would like to know the cost on aveage of hiing new alicants X andom vaiable equal to numbe times new eson hied X = i X i

Randomized hiing oblem(n) X andom vaiable equal to numbe times new eson hied X = Whee i X i X i X i = I{i} ae indicato andom vaiables: 1 if candidate i hied 0 if candidate i not hied Fo notation, we can do the I symbol: X = 1 if candidate i hied i 0 if candidate i not hied

Randomized hiing oblem(n) X andom vaiable equal to numbe times new eson hied X = E X i X i n i=1 [ ] = E X i = n i=1 E [ X ] i Lineaity exectations

Randomized hiing oblem(n) X andom vaiable equal to numbe times new eson hied X = E X i X i n i=1 [ ] = E X i E[ X ] i = P( i) =? = n i=1 E [ X ] i Pob candidate i hied

Randomized hiing oblem(n) * X andom vaiable equal to numbe times new eson hied X = E X n i=1 X i n i=1 [ ] = E X i = n i=1 E [ X ] i E[ X ] i = P( i) = 1 i Pob candidate i hied E[ X] = n 1 =? i i=1 Put back in *

Randomized hiing oblem(n) X andom vaiable equal to numbe times new eson hied X = n i=1 E[ X] = X i n 1 = 1 i 1 + 1 2 + 1 3 +... + 1 n = i=1 ln(n) + O(1) Hamonic seies

Randomized hiing oblem(n) X andom vaiable equal to numbe times new eson hied X = n i=1 E[ X] = X i n 1 = 1 i 1 + 1 2 + 1 3 +... + 1 n = i=1 ln(n) + O(1) Vaious ways to ove: One easy way to see: Hamonic seies

Randomized hiing oblem(n) n 1 = 1 i 1 + 1 2 + 1 3 +... + 1 n = i=1 ln(n) + O(1) Hamonic seies Vaious ways to see: k 1 > n n=1 k+1 1 dx = ln(k +1) x 1

Randomized hiing oblem(n) Cost of hiing new candidate C h So on aveage cost C h ln(n) What about wost case?

Randomized hiing oblem(n) Cost of hiing new candidate C h So on aveage cost C h ln(n) Comae to wost case C h n

Quicksot Inut: n numbes Outut: soted numbes, e.g., in inceasing ode O(n logn) on aveage Sots in lace, unlike Mege sot Elegant

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,)

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) We can see it is a divide and conque, but what is secial?

Patition 1. Pick ivot element in aay A (fo now, we ll choose last element) 2. Reaange A so that elements befoe ivot ae smalle, and elements afte ivot ae lage Pivot Examle: A = [8 6 1 3 7 5 2 4]

Patition Examle: A = [8 6 1 3 7 5 2 4] Afte Patition: A = [1 3 2 4 5 7 6 8] < ivot > ivot Pivot in its ight sot

Patition Animation: htt://www.cs.miami.edu/~but/leaning/csc517.101/wokbook/atition.html

Patition Patition(A,,) 1. x=a[ ] 2. i=-1 3. fo j = to -1 4. if A[ j ] <= x 5. i = I + 1;; 6. swa A[ i ] with A[ j ] 7. swa A[ i+1 ] with A[ ] 8. etun i+1 O(?)

Patition Patition(A,,) 1. x=a[ ] ivot 2. i=-1 3. fo j = to -1 4. if A[ j ] <= x 5. i = i + 1 6. swa A[ i ] with A[ j ] 7. swa A[ i+1 ] with A[ ] 8. etun i+1 O(n) Why?

Patition Patition(A,,) 1. x=a[ ] ivot 2. i=-1 3. fo j = to -1 4. if A[ j ] <= x 5. i = i + 1 6. swa A[ i ] with A[ j ] 7. swa A[ i+1 ] with A[ ] 8. etun i+1 O(n) Why? Fo each j, at most one swa

Patition Reviewing evious mateial Loo invaiant?

Patition i j Loo invaiant? i kees tack of ivot location j kees tack of next element to chk Befoe the fo loo at given j 1. All elements in A[..i] <= ivot 2. All elements in A[i+1..j-1] > ivot 3. A[] = ivot

Patition i j Loo invaiant? i kees tack of ivot location j kees tack of next element to chk i 1 4 6 8 0 3 9 5 j i j A[]: ivot A[j.. 1]: not yet examined A[i+1.. j 1]: known to be > ivot A[.. i]: known to be ivot

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) When will Patition do a bad job?

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) When will Patition do a bad job? When the atition is fo zeo elements vesus n-1 T(n) = T(n 1) + Θ(n) = Θ(n 2 )

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) When will Patition do a good job?

Quicksot q Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) When will Patition do a good job? When the atition is oughly equal in tems of numbes smalle than and geate than ivot T(n) = 2T(n / 2) + Θ(n) = Θ(nlogn) (as in Mege sot)

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) How do we choose the ivot oint?? So that good ON AVERAGE?

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) KEY APPROACH: Choose ivot RANDOMLY

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) Why might a andom choice be good enough? We saw that equal slit good;; What about a 3 to 1, o 9 to 1 slit?

Quicksot q Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) What about a 3 to 1, o 9 to 1 slit?

Quicksot q Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) What about a 9 to 1 slit? T(n) = T(9n /10) + T(n /10) + Θ(n) =?

Quicksot n cn log 10 n 1 10 n 9 10 n 1 n 9 n 9 n 81 n 100 100 100 100 cn cn log 10=9 n 1 81 1000 n 729 1000 n cn cn What about a 9 to 1 slit? 1 cn O.nlg n/ T(n) = T(9n /10) + T(n /10) + Θ(n) = Θ(nlogn)

Quicksot Quicksot(A,, ) 1. If < 2. q = Patition(A,,) 3. Quicksot(A,,q-1) 4. Quicksot(A,q+1,) Why might a andom choice be good enough? Even a 9 to 1, o 3 to 1 slit, is O(n log n) Might not be so had to get on aveage??

Quicksot on aveage un time We ll ove that aveage un time with andom ivots fo any inut aay is O(n log n) Randomness is in choosing ivot Aveage as good as best case! Next class