CSC373 Week 11: Randomized Algorithmsnisarg/teaching/373f20/...Randomized Algorithms 373F20 - Nisarg...

55
CSC373 Week 11: Randomized Algorithms 373F20 - Nisarg Shah 1

Transcript of CSC373 Week 11: Randomized Algorithmsnisarg/teaching/373f20/...Randomized Algorithms 373F20 - Nisarg...

  • CSC373

    Week 11: Randomized Algorithms

    373F20 - Nisarg Shah 1

  • Randomized Algorithms

    373F20 - Nisarg Shah 2

    Deterministic AlgorithmInput Output

    Randomized AlgorithmInput

    OutputRandomness

  • Randomized Algorithms

    373F20 - Nisarg Shah 3

    โ€ข Running time

    โžข Harder goal: the running time should always be small

    o Regardless of both the input and the random coin flips

    โžข Easier goal: the running time should be small in expectation

    o Expectation over random coin flips

    o But it should still be small for every input (i.e. worst-case)

    โ€ข Approximation Ratio

    โžข The objective value of the solution returned should, in expectation, be close to the optimum objective value

    o Once again, the expectation is over random coin flips

    o The approximation ratio should be small for every input

  • Derandomization

    373F20 - Nisarg Shah 4

    โ€ข After coming up with a randomized approximation algorithm, one might ask if it can be โ€œderandomizedโ€โžข Informally, the randomized algorithm is making random choices that,

    in expectation, turn out to be good

    โžข Can we make these โ€œgoodโ€ choices deterministically?

    โ€ข For some problemsโ€ฆโžข It may be easier to first design a simple randomized approximation

    algorithm and then de-randomize itโ€ฆ

    โžข Than to try to directly design a deterministic approximation algorithm

  • Recap: Probability Theory

    373F20 - Nisarg Shah 5

    โ€ข Random variable ๐‘‹โžข Discrete

    o Takes value ๐‘ฃ1 with probability ๐‘1, ๐‘ฃ2 w.p. ๐‘2, โ€ฆ

    o Expected value ๐ธ ๐‘‹ = ๐‘1 โ‹… ๐‘ฃ1 + ๐‘2 โ‹… ๐‘ฃ2 + โ‹ฏ

    o Examples: coin toss, the roll of a six-sided die, โ€ฆ

    โžข Continuous

    o Has a probability density function (pdf) ๐‘“

    o Its integral is the cumulative density function (cdf) ๐น

    โ€ข ๐น ๐‘ฅ = Pr ๐‘‹ โ‰ค ๐‘ฅ = โˆžโˆ’๐‘ฅ

    ๐‘“ ๐‘ก ๐‘‘๐‘ก

    o Expected value ๐ธ ๐‘‹ = โˆžโˆ’โˆž

    ๐‘ฅ ๐‘“ ๐‘ฅ ๐‘‘๐‘ฅ

    o Examples: normal distribution, exponential distribution, uniform distribution over [0,1], โ€ฆ

  • Recap: Probability Theory

    373F20 - Nisarg Shah 6

    โ€ข Things you should be aware ofโ€ฆโžข Conditional probabilities

    โžข Conditional expectations

    โžข Independence among random variables

    โžข Moments of random variables

    โžข Standard discrete distributions: uniform over a finite set, Bernoulli, binomial, geometric, Poisson, โ€ฆ

    โžข Standard continuous distributions: uniform over intervals, Gaussian/normal, exponential, โ€ฆ

  • Three Pillars

    373F20 - Nisarg Shah 7

    โ€ข Deceptively simple, but incredibly powerful!

    โ€ข Many many many many probabilistic results are just interesting applications of these three results

    Linearity of Expectation Union Bound Chernoff Bound

  • Three Pillars

    373F20 - Nisarg Shah 8

    โ€ข Linearity of expectationโžข ๐ธ ๐‘‹ + ๐‘Œ = ๐ธ ๐‘‹ + ๐ธ[๐‘Œ]

    โžข This does not require any independence assumptions about ๐‘‹ and ๐‘Œ

    โžข E.g. if you want to find out how many people will attend your party on average, just ask each person the probability with which they will attend and sum up the probabilities

    o It does not matter whether some of them are friends and either all will attend together or none will attend

  • Three Pillars

    373F20 - Nisarg Shah 9

    โ€ข Union boundโžข For any two events ๐ด and ๐ต, Pr ๐ด โˆช ๐ต โ‰ค Pr ๐ด + Pr[๐ต]

    โžข โ€œProbability that at least one of the ๐‘› events ๐ด1, โ€ฆ , ๐ด๐‘› will occur is at most ฯƒ๐‘– Pr ๐ด๐‘– โ€

    โžข Typically, ๐ด1, โ€ฆ , ๐ด๐‘› are โ€œbad eventsโ€

    o You do not want any of them to occur

    o If you can individually bound Pr ๐ด๐‘– โ‰ค ฮค1

    2๐‘› for each ๐‘–, then probability that at least one them occurs โ‰ค ฮค1 2

    o Thus, with probability โ‰ฅ ฮค1 2, none of the bad events will occur

    โ€ข Chernoff bound & Hoeffdingโ€™s inequalityโžข Read up!

  • 373F20 - Nisarg Shah 10

    Exact Max-๐‘˜-SAT

  • Exact Max-๐‘˜-SAT

    373F20 - Nisarg Shah 11

    โ€ข Problem (recall)โžข Input: An exact ๐‘˜-SAT formula ๐œ‘ = ๐ถ1 โˆง ๐ถ2 โˆง โ‹ฏ โˆง ๐ถ๐‘š,

    where each clause ๐ถ๐‘– has exactly ๐‘˜ literals, and a weight ๐‘ค๐‘– โ‰ฅ 0 of each clause ๐ถ๐‘–

    โžข Output: A truth assignment ๐œ maximizing the number (or total weight) of clauses satisfied under ๐œ

    โžข Let us denote by ๐‘Š(๐œ) the total weight of clauses satisfied under ๐œ

  • Exact Max-๐‘˜-SAT

    373F20 - Nisarg Shah 12

    โ€ข Recall our local searchโžข ๐‘๐‘‘(๐œ) = set of all truth assignments which can be obtained by

    changing the value of at most ๐‘‘ variables in ๐œ

    โ€ข Result 1: Neighborhood ๐‘1(๐œ) โ‡’ ฮค2

    3-apx for Exact Max-2-SAT.

    โ€ข Result 2: Neighborhood ๐‘1 ๐œ โˆช ๐œ๐‘ โ‡’ ฮค3 4-apx for Exact Max-

    2-SAT.

    โ€ข Result 3: Neighborhood ๐‘1 ๐œ + oblivious local search โ‡’ ฮค3

    4-apx for Exact Max-2-SAT.

  • Exact Max-๐‘˜-SAT

    373F20 - Nisarg Shah 13

    โ€ข Recall our local searchโžข ๐‘๐‘‘(๐œ) = set of all truth assignments which can be obtained by

    changing the value of at most ๐‘‘ variables in ๐œ

    โ€ข We claimed that ยพ-apx for Exact Max-2-SAT can be

    generalized to 2๐‘˜โˆ’1

    2๐‘˜-apx for Exact Max-๐‘˜-SAT

    โžข Algorithm becomes slightly more complicated

    โ€ข What can we do with randomized algorithms?

  • Exact Max-๐‘˜-SAT

    373F20 - Nisarg Shah 14

    โ€ข Recall: โžข We have a formula ๐œ‘ = ๐ถ1 โˆง ๐ถ2 โˆง โ‹ฏ โˆง ๐ถ๐‘šโžข Variables = ๐‘ฅ1, โ€ฆ , ๐‘ฅ๐‘›, literals = variables or their negations

    โžข Each clause contains exactly ๐‘˜ literals

    โ€ข The most naรฏve randomized algorithmโžข Set each variable to TRUE with probability ยฝ and to FALSE with

    probability ยฝ

    โ€ข How good is this?

  • Exact Max-๐‘˜-SAT

    373F20 - Nisarg Shah 15

    โ€ข Recall: โžข We have a formula ๐œ‘ = ๐ถ1 โˆง ๐ถ2 โˆง โ‹ฏ โˆง ๐ถ๐‘šโžข Variables = ๐‘ฅ1, โ€ฆ , ๐‘ฅ๐‘›, literals = variables or their negations

    โžข Each clause contains exactly ๐‘˜ literals

    โ€ข Let ๐œ be a random assignment

    โžข For each clause ๐ถ๐‘–: Pr[๐ถ๐‘– is not satisfied] = เต—1

    2๐‘˜(WHY?)

    o Hence, Pr[๐ถ๐‘– is satisfied] = เต—2๐‘˜โˆ’1

    2๐‘˜

    โžข ๐ธ ๐‘Š ๐œ = ฯƒ๐‘–=1๐‘š ๐‘ค๐‘– โ‹… Pr[๐ถ๐‘– is satisfied] (WHY?)

    โžข ๐ธ ๐‘Š ๐œ =2๐‘˜โˆ’1

    2๐‘˜โ‹… ฯƒ๐‘–=1

    ๐‘š ๐‘ค๐‘– โ‰ฅ2๐‘˜โˆ’1

    2๐‘˜โ‹… ๐‘‚๐‘ƒ๐‘‡

  • Derandomization

    373F20 - Nisarg Shah 16

    โ€ข Can we derandomize this algorithm?โžข What are the choices made by the algorithm?

    o Setting the values of ๐‘ฅ1, ๐‘ฅ2, โ€ฆ , ๐‘ฅ๐‘›โžข How do we know which set of choices is good?

    โ€ข Idea:โžข Do not think about all the choices at once.

    โžข Think about them one by one.

    โžข Goal: Gradually convert the random assignment ๐œ to a deterministic assignment ฦธ๐œ such that ๐‘Š ฦธ๐œ โ‰ฅ ๐ธ ๐‘Š ๐œ

    o Combining with ๐ธ ๐‘Š ๐œ โ‰ฅ2๐‘˜โˆ’1

    2๐‘˜โ‹… ๐‘‚๐‘ƒ๐‘‡ will give the desired

    deterministic approximation ratio

  • Derandomization

    373F20 - Nisarg Shah 17

    โ€ข Start with the random assignment ๐œ and writeโ€ฆ

    ๐ธ ๐‘Š ๐œ = Pr ๐‘ฅ1 = ๐‘‡ โ‹… ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡ + Pr ๐‘ฅ1 = ๐น โ‹… ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐น= เต—1 2 โ‹… ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡ + เต—

    12 โ‹… ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐น

    โžข Hence, max ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡ , ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐น โ‰ฅ ๐ธ ๐‘Š ๐œ

    o What is ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡ ?

    โ€ข It is the expected weight when setting ๐‘ฅ1 = ๐‘‡ deterministically but still keeping ๐‘ฅ2, โ€ฆ , ๐‘ฅ๐‘› random

    โžข If we can compute both ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡ and ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐น , and pick the better oneโ€ฆ

    o Then we can set ๐‘ฅ1 deterministically without degrading the expected objective value

  • โ€ข After deterministically making the right choice for ๐‘ฅ1 (say T), we can apply the same logic to ๐‘ฅ2

    ๐ธ ๐‘Š ๐œ |๐‘ฅ1 = ๐‘‡ = เต—1

    2 โ‹… ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡, ๐‘ฅ2 = ๐‘‡

    + เต—1 2 โ‹… ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘‡, ๐‘ฅ2 = ๐น

    โžข Pick the better of the two conditional expectations

    โ€ข Derandomized Algorithm:โžข For ๐‘– = 1, โ€ฆ , ๐‘›

    o Let ๐‘ง๐‘– = ๐‘‡ if ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐‘‡ โ‰ฅ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐น , and ๐‘ง๐‘– = ๐น otherwise

    o Set ๐‘ฅ๐‘– = ๐‘ง๐‘–

    Derandomization

    373F20 - Nisarg Shah 18

  • โ€ข This is called the method of conditional expectationsโžข If weโ€™re happy when making a choice at random, we should be at least

    as happy conditioned on at least one of the possible values of that choice

    โ€ข Remaining question:โžข How do we compute & compare the two conditional expectations:

    ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐‘‡ and ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐น ?

    Derandomization

    373F20 - Nisarg Shah 19

  • Derandomization

    373F20 - Nisarg Shah 20

    โ€ข ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐‘‡โžข ฯƒ๐‘Ÿ ๐‘ค๐‘Ÿ โ‹… Pr[๐ถ๐‘Ÿ is satisfied ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐‘‡โžข Set the values of ๐‘ฅ1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1, ๐‘ฅ๐‘–โžข If ๐ถ๐‘Ÿ resolves to TRUE already, the corresponding probability is 1

    โžข If ๐ถ๐‘Ÿ resolves to FALSE already, the corresponding probability is 0

    โžข Otherwise, if there are โ„“ literals left in ๐ถ๐‘Ÿ after setting ๐‘ฅ1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1, ๐‘ฅ๐‘–,

    the corresponding probability is 2โ„“โˆ’1

    2โ„“

    โ€ข Compute ๐ธ ๐‘Š ๐œ ๐‘ฅ1 = ๐‘ง1, โ€ฆ , ๐‘ฅ๐‘–โˆ’1 = ๐‘ง๐‘–โˆ’1, ๐‘ฅ๐‘– = ๐น similarly

  • Max-SAT

    373F20 - Nisarg Shah 21

    โ€ข Simple randomized algorithm

    โžข

    2๐‘˜โˆ’1

    2๐‘˜โˆ’approximation for Max-๐‘˜-SAT

    โžข Max-3-SAT โ‡’ ฮค7 8o [Hรฅstad]: This is the best possible assuming P โ‰  NP

    โžข Max-2-SAT โ‡’ ฮค3 4 = 0.75

    o The best known approximation is 0.9401 using semi-definite programming and randomized rounding

    โžข Max-SAT โ‡’ ฮค1 2o Max-SAT = no restriction on the number of literals in each clause

    o The best known approximation is 0.7968, also using semi-definite programming and randomized rounding

  • Max-SAT

    373F20 - Nisarg Shah 22

    โ€ข Better approximations for Max-SATโžข Semi-definite programming is out of the scope

    โžข But we will see the simpler โ€œLP relaxation + randomized roundingโ€ approach that gives 1 โˆ’ ฮค1 ๐‘’ โ‰ˆ 0.6321 approximation

    โ€ข Max-SAT:โžข Input: ๐œ‘ = ๐ถ1 โˆง ๐ถ2 โˆง โ‹ฏ โˆง ๐ถ๐‘š, where each clause ๐ถ๐‘– has weight ๐‘ค๐‘– โ‰ฅ

    0 (and can have any number of literals)

    โžข Output: Truth assignment that approximately maximizes the weight of clauses satisfied

  • LP Formulation of Max-SAT

    373F20 - Nisarg Shah 23

    โ€ข First, IP formulation:โžข Variables:

    o ๐‘ฆ1, โ€ฆ , ๐‘ฆ๐‘› โˆˆ {0,1}

    โ€ข ๐‘ฆ๐‘– = 1 iff variable ๐‘ฅ๐‘– = TRUE in Max-SAT

    o ๐‘ง1, โ€ฆ , ๐‘ง๐‘š โˆˆ {0,1}

    โ€ข ๐‘ง๐‘— = 1 iff clause ๐ถ๐‘— is satisfied in Max-SAT

    o Program:

    Maximize ฮฃ๐‘— ๐‘ค๐‘— โ‹… ๐‘ง๐‘—s.t.ฮฃ๐‘ฅ๐‘–โˆˆ๐ถ๐‘— ๐‘ฆ๐‘– + ฮฃ าง๐‘ฅ๐‘–โˆˆ๐ถ๐‘— 1 โˆ’ ๐‘ฆ๐‘– โ‰ฅ ๐‘ง๐‘— โˆ€๐‘— โˆˆ 1, โ€ฆ , ๐‘š

    ๐‘ฆ๐‘– , ๐‘ง๐‘— โˆˆ 0,1 โˆ€๐‘– โˆˆ 1, โ€ฆ , ๐‘› , ๐‘— โˆˆ 1, โ€ฆ , ๐‘š

  • LP Formulation of Max-SAT

    373F20 - Nisarg Shah 24

    โ€ข LP relaxation:โžข Variables:

    o ๐‘ฆ1, โ€ฆ , ๐‘ฆ๐‘› โˆˆ [0,1]

    โ€ข ๐‘ฆ๐‘– = 1 iff variable ๐‘ฅ๐‘– = TRUE in Max-SAT

    o ๐‘ง1, โ€ฆ , ๐‘ง๐‘š โˆˆ [0,1]

    โ€ข ๐‘ง๐‘— = 1 iff clause ๐ถ๐‘— is satisfied in Max-SAT

    o Program:

    Maximize ฮฃ๐‘— ๐‘ค๐‘— โ‹… ๐‘ง๐‘—s.t.ฮฃ๐‘ฅ๐‘–โˆˆ๐ถ๐‘— ๐‘ฆ๐‘– + ฮฃ าง๐‘ฅ๐‘–โˆˆ๐ถ๐‘— 1 โˆ’ ๐‘ฆ๐‘– โ‰ฅ ๐‘ง๐‘— โˆ€๐‘— โˆˆ 1, โ€ฆ , ๐‘š

    ๐‘ฆ๐‘– , ๐‘ง๐‘— โˆˆ [0,1] โˆ€๐‘– โˆˆ 1, โ€ฆ , ๐‘› , ๐‘— โˆˆ 1, โ€ฆ , ๐‘š

  • Randomized Rounding

    373F20 - Nisarg Shah 25

    โ€ข Randomized roundingโžข Find the optimal solution (๐‘ฆโˆ—, ๐‘งโˆ—) of the LP

    โžข Compute a random IP solution เทœ๐‘ฆ such that

    o Each เทœ๐‘ฆ๐‘– = 1 with probability ๐‘ฆ๐‘–โˆ— and 0 with probability 1 โˆ’ ๐‘ฆ๐‘–

    โˆ—

    o Independently of other เทœ๐‘ฆ๐‘–โ€™s

    o The output of the algorithm is the corresponding truth assignment

    โžข What is Pr[๐ถ๐‘— is satisfied] if ๐ถ๐‘— has ๐‘˜ literals?

    1 โˆ’ ฮ ๐‘ฅ๐‘–โˆˆ๐ถ๐‘— 1 โˆ’ ๐‘ฆ๐‘–โˆ— โ‹… ฮ  าง๐‘ฅ๐‘–โˆˆ๐ถ๐‘— ๐‘ฆ๐‘–

    โˆ—

    โ‰ฅ 1 โˆ’ฮฃ๐‘ฅ๐‘–โˆˆ๐ถ๐‘— 1 โˆ’ ๐‘ฆ๐‘–

    โˆ— + ฮฃ าง๐‘ฅ๐‘–โˆˆ๐ถ๐‘— ๐‘ฆ๐‘–โˆ—

    ๐‘˜

    ๐‘˜

    โ‰ฅ 1 โˆ’๐‘˜ โˆ’ ๐‘ง๐‘—

    โˆ—

    ๐‘˜

    ๐‘˜

    AM-GM inequality LP constraint

  • Randomized Rounding

    373F20 - Nisarg Shah 26

    โ€ข Claim

    โžข 1 โˆ’ 1 โˆ’๐‘ง

    ๐‘˜

    ๐‘˜โ‰ฅ 1 โˆ’ 1 โˆ’

    1

    ๐‘˜

    ๐‘˜โ‹… ๐‘ง for all ๐‘ง โˆˆ [0,1] and ๐‘˜ โˆˆ โ„•

    โ€ข Assuming the claim:

    Pr ๐ถ๐‘— is satisfied โ‰ฅ 1 โˆ’๐‘˜โˆ’๐‘ง๐‘—

    โˆ—

    ๐‘˜

    ๐‘˜

    โ‰ฅ 1 โˆ’ 1 โˆ’1

    ๐‘˜

    ๐‘˜โ‹… ๐‘ง๐‘—

    โˆ— โ‰ฅ 1 โˆ’1

    ๐‘’โ‹… ๐‘ง๐‘—

    โˆ—

    โ€ข Hence,

    ๐”ผ[#weight of clauses satisfied] โ‰ฅ 1 โˆ’1

    eฯƒ๐‘— ๐‘ค๐‘— โ‹… ๐‘ง๐‘—

    โˆ— โ‰ฅ 1 โˆ’1

    ๐‘’โ‹… ๐‘‚๐‘ƒ๐‘‡

    Standard inequality

    Optimal LP objective โ‰ฅ optimal ILP objective

  • Randomized Rounding

    373F20 - Nisarg Shah 27

    โ€ข Claim

    โžข 1 โˆ’ 1 โˆ’๐‘ง

    ๐‘˜

    ๐‘˜โ‰ฅ 1 โˆ’ 1 โˆ’

    1

    ๐‘˜

    ๐‘˜โ‹… ๐‘ง for all ๐‘ง โˆˆ [0,1] and ๐‘˜ โˆˆ โ„•

    โ€ข Proof of claim:โžข True at ๐‘ง = 0 and ๐‘ง = 1 (same quantity on both sides)

    โžข For 0 โ‰ค ๐‘ง โ‰ค 1:

    o LHS is a convex function

    o RHS is a linear function

    o Hence, LHS โ‰ฅ RHS โˆŽ

  • Improving Max-SAT Apx

    373F20 - Nisarg Shah 28

    โ€ข Best of both worlds:โžข Run both โ€œLP relaxation + randomized roundingโ€ and โ€œnaรฏve

    randomized algorithmโ€

    โžข Return the best of the two solutions

    โžข Claim without proof: This achieves a ฮค3 4 = 0.75 approximation!

    o This algorithm can be derandomized.

    โžข Recall:

    o โ€œnaรฏve randomizedโ€ = independently set each variable to TRUE/FALSE with probability 0.5 each, which only gives ฮค1 2 = 0.5approximation by itself

  • โ€ข Max-2-SAT is NP-hard (we didnโ€™t prove this!)

    โ€ข But 2-SAT can be efficiently solvedโžข โ€œGiven a 2-CNF formula, check whether all clauses can be satisfied

    simultaneously.โ€

    โ€ข Algorithm:โžข Repeatedly eliminate a clause with one literal & set the literal to true

    โžข Create a graph with each remaining literal as a vertex

    โžข For every clause (๐‘ฅ โˆจ ๐‘ฆ), add two edges: าง๐‘ฅ โ†’ ๐‘ฆ and เดค๐‘ฆ โ†’ ๐‘ฅ

    o ๐‘ข โ†’ ๐‘ฃ means if ๐‘ข is true, ๐‘ฃ must be true

    โžข Formula is satisfiable iff no path from ๐‘ฅ to าง๐‘ฅ or าง๐‘ฅ to ๐‘ฅ for any ๐‘ฅ

    o Can be checked in polynomial time

    Back to 2-SAT

    373F20 - Nisarg Shah 29

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 30

    โ€ข Hereโ€™s a cute randomized algorithm by Papadimitriou [1991]

    โ€ข Algorithm:โžข Start with an arbitrary assignment.

    โžข While there is an unsatisfied clause ๐ถ = (๐‘ฅ โˆจ ๐‘ฆ)

    o Pick one of the two literals with equal probability.

    o Flip the variable value so that ๐ถ is satisfied.

    โ€ข But canโ€™t this hurt the other clauses?โžข In a given step, yes.

    โžข But in expectation, we will still make progress.

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 31

    โ€ข Theorem:โžข If there is a satisfying assignment ๐œโˆ—, then this algorithm reaches a

    satisfying assignment in ๐‘‚ ๐‘›2 expected time.

    โ€ข Proof: โžข Fix a satisfying assignment ๐œโˆ—

    โžข Let ๐œ0 be the starting assignment

    โžข Let ๐œ๐‘– be the assignment after ๐‘– iterations

    โžข Consider the โ€œhamming distanceโ€ ๐‘‘๐‘– between ๐œ๐‘– and ๐œโˆ—

    o Number of coordinates in which the two differ

    o ๐‘‘๐‘– โˆˆ {0,1, โ€ฆ , ๐‘›}

    โžข Claim: the algorithm hits ๐‘‘๐‘– = 0 in ๐‘‚ ๐‘›2 iterations in expectation,

    unless it stops before that

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 32

    โ€ข Observation: ๐‘‘๐‘–+1 = ๐‘‘๐‘– โˆ’ 1 or ๐‘‘๐‘–+1 = ๐‘‘๐‘– + 1โžข Because we change one variable in each iteration.

    โ€ข Claim: Pr ๐‘‘๐‘–+1 = ๐‘‘๐‘– โˆ’ 1 โ‰ฅ 1/2

    โ€ข Proof:โžข Iteration ๐‘– considers an unsatisfied clause ๐ถ = (๐‘ฅ โˆจ ๐‘ฆ)

    โžข ๐œโˆ— satisfies at least one of ๐‘ฅ or ๐‘ฆ, while ๐œ๐‘– satisfies neither

    โžข Because we pick a literal randomly, w.p. at least ยฝ we pick one where ๐œ๐‘– and ๐œ

    โˆ— differ and decrease the distance

    โžข Q: Why did we need an unsatisfied clause? What if we pick one of ๐‘›variables randomly and flip it?

  • Random Walk 2-SAT

    373F20 - Nisarg Shah 33

    โ€ข Answer:

    โžข We want the distance to decrease with probability at least 1

    2no

    matter how close or far we are from ๐œโˆ—

    โžข If we are already close, choosing a variable at random will likely choose one where ๐œ and ๐œโˆ— already match

    โžข Flipping this variable will increase the distance with high probability

    โžข An unsatisfied clause narrows it down to two variables s.t. ๐œ and ๐œโˆ—

    differ on at least one of them

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 34

    โ€ข Observation: ๐‘‘๐‘–+1 = ๐‘‘๐‘– โˆ’ 1 or ๐‘‘๐‘–+1 = ๐‘‘๐‘– + 1

    โ€ข Claim: Pr ๐‘‘๐‘–+1 = ๐‘‘๐‘– โˆ’ 1 โ‰ฅ 1/2

    โ€ข How does this help?

    0 1 2 3 4 ๐‘›5

    โ‰ฅ1

    2โ‰ค

    1

    2โ‰ฅ

    1

    2โ‰ค

    1

    2

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 35

    โ€ข How does this help?โžข Can view this as a โ€œMarkov chainโ€ and use known results

    on โ€œhitting timeโ€

    โžข But letโ€™s prove it using elementary methods

    0 1 2 3 4 ๐‘›5

    โ‰ฅ1

    2โ‰ค

    1

    2โ‰ฅ

    1

    2โ‰ค

    1

    2

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 36

    โ€ข For ๐‘˜ > โ„“, define:โžข ๐‘‡๐‘˜,โ„“ = expected number of iterations it takes to hit distance โ„“

    for the first time when you start at distance ๐‘˜

    โ€ข ๐‘‡๐‘–+1,๐‘– โ‰ค1

    2โˆ— 1 +

    1

    2โˆ— 1 + ๐‘‡๐‘–+2,๐‘–

    =1

    2โˆ— (1) +

    1

    2โˆ— 1 + ๐‘‡๐‘–+2,๐‘–+1 + ๐‘‡๐‘–+1,๐‘–

    โ€ข Simplifying: โžข ๐‘‡๐‘–+1,๐‘– โ‰ค 2 + ๐‘‡๐‘–+2,๐‘–+1 โ‰ค 4 + ๐‘‡๐‘–+3,๐‘–+2 โ‰ค โ‹ฏ โ‰ค ๐‘‚ ๐‘› + ๐‘‡๐‘›,๐‘›โˆ’1 โ‰ค ๐‘‚ ๐‘›

    o Uses ๐‘‡๐‘›,๐‘›โˆ’1 = 1 (Why?)

    โ€ข ๐‘‡๐‘›,0 โ‰ค ๐‘‡๐‘›,๐‘›โˆ’1 + โ‹ฏ + ๐‘‡1,0 = ๐‘‚ ๐‘›2

    Which pillar did we use?

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 37

    โ€ข Can view this algorithm as a โ€œdrunken local searchโ€โžข We are searching the local neighborhood

    โžข But we donโ€™t ensure that we necessarily improve

    โžข We just ensure that in expectation, we arenโ€™t hurt

    โžข Hope to reach a feasible solution in polynomial time

    โ€ข Schรถning extended this technique to ๐‘˜-SATโžข Schรถningโ€™s algorithm no longer runs in polynomial time, but this is

    okay because ๐‘˜-SAT is NP-hard

    โžข It still improves upon the naรฏve 2๐‘›

    โžข Later derandomized by Moser and Scheder [2011]

  • Schรถningโ€™s Algorithm for ๐‘˜-SAT

    373F20 - Nisarg Shah 38

    โ€ข Algorithm:โžข Choose a random assignment ๐œ

    โžข Repeat 3๐‘› times (๐‘› = #variables)

    o If ๐œ satisfies the CNF, stop

    o Else, pick an arbitrary unsatisfied clause and flip a random literal in the clause

  • Schรถningโ€™s Algorithm

    373F20 - Nisarg Shah 39

    โ€ข Randomized algorithm with one-sided errorโžข If the CNF is satisfiable, it finds an assignment with probability at

    least 1

    2โ‹…

    ๐‘˜

    ๐‘˜โˆ’1

    ๐‘›

    โžข If the CNF is unsatisfiable, it never finds an assignment

    โ€ข Expected #times we need to repeat in order to find a

    satisfying assignment when one exists: 2 1 โˆ’ 1๐‘˜

    ๐‘›

    โžข For ๐‘˜ = 3, this gives ๐‘‚(1.3333๐‘›)

    โžข For ๐‘˜ = 4, this gives ๐‘‚ 1.5๐‘›

  • Best Known Results

    373F20 - Nisarg Shah 40

    โ€ข 3-SAT

    โ€ข Deterministicโžข Derandomized Schรถningโ€™s algorithm: ๐‘‚(1.3333๐‘›)

    โžข Best known: ๐‘‚(1.3303๐‘›) [HSSW]

    o If we are assured that there is a unique satisfying assignment: ๐‘‚(1.3071๐‘›) [PPSZ]

    โ€ข Randomizedโžข Nothing better known without one-sided error

    โžข With one-sided error, best known is ๐‘‚ 1.30704๐‘› [Modified PPSZ]

  • Random Walk + 2-SAT

    373F20 - Nisarg Shah 41

    โ€ข Random walks are not only of theoretical interestโžข WalkSAT is a practical SAT algorithm

    โžข At each iteration, pick an unsatisfied clause at random

    โžข Pick a variable in the unsatisfied clause to flip:

    o With some probability, pick at random.

    o With the remaining probability, pick one that will make the fewest previously satisfied clauses unsatisfied

    โžข Restart a few times (avoids being stuck in local minima)

    โ€ข Faster than โ€œintelligent local searchโ€ (GSAT)โžข Flip the variable that satisfies most clauses

  • Random Walks on Graphs

    373F20 - Nisarg Shah 42

    โ€ข Aleliunas et al. [1979]โžข Let ๐บ be a connected undirected graph. Then a random walk starting

    from any vertex will cover the entire graph (visit each vertex at least once) in ๐‘‚(๐‘š๐‘›) steps.

    โ€ข Limiting probability distribution

    โžข In the limit, the random walk will visit a vertex with degree ๐‘‘๐‘– in ๐‘‘๐‘–

    2๐‘šfraction of the steps

    โ€ข Markov chains โžข Generalize to directed (possibly infinite) graphs with unequal edge

    traversal probabilities

  • 373F20 - Nisarg Shah 43

    Randomization for Sublinear Running Time

  • Sublinear Running Time

    373F20 - Nisarg Shah 44

    โ€ข Given an input of length ๐‘›, we want an algorithm that runs in time ๐‘œ(๐‘›)

    โžข ๐‘œ(๐‘›) examples: log ๐‘› , ๐‘›, ๐‘›0.999,๐‘›

    log ๐‘›, โ€ฆ

    โžข The algorithm doesnโ€™t even get to read the full input!

    โ€ข There are four possibilities:โžข Exact vs inexact: whether the algorithm always returns the

    correct/optimal solution or only does so with high probability (or gives some approximation)

    โžข Worst-case versus expected running time: whether the algorithm always takes ๐‘œ(๐‘›) time or only does so in expectation (but still on every instance)

  • 373F20 - Nisarg Shah 45

    Exact algorithms, expected sublinear time

  • Searching in Sorted List

    373F20 - Nisarg Shah 46

    โ€ข Input: A sorted doubly linked list with ๐‘› elements.โžข Imagine you have an array ๐ด with ๐‘‚(1) access to ๐ด[๐‘–]

    โžข ๐ด[๐‘–] is a tuple (๐‘ฅ๐‘– , ๐‘๐‘– , ๐‘›๐‘–)

    o Value, index of previous element, index of next element.

    โžข Sorted: ๐‘ฅ๐‘๐‘– โ‰ค ๐‘ฅ๐‘– โ‰ค ๐‘ฅ๐‘›๐‘–

    โ€ข Task: Given ๐‘ฅ, check if there exists ๐‘– s.t. ๐‘ฅ = ๐‘ฅ๐‘–

    โ€ข Goal: We will give a randomized + exact algorithm with expected running time ๐‘‚ ๐‘› !

  • Searching in Sorted List

    373F20 - Nisarg Shah 47

    โ€ข Motivation: โžข Often we deal with large datasets that are stored in a large file on

    disk, or possibly broken into multiple files

    โžข Creating a new, sorted version of the dataset is expensive

    โžข It is often preferred to โ€œimplicitly sortโ€ the data by simply adding previous-next pointers along with each element

    โžข Would like algorithms that can operate on such implicitly sorted versions and yet achieve sublinear running time

    o Just like binary search achieves for an explicitly sorted array

  • Searching in Sorted List

    373F20 - Nisarg Shah 48

    Algorithm:โžข Select ๐‘› random indices ๐‘…

    โžข Access ๐‘ฅ๐‘— for each ๐‘— โˆˆ ๐‘…

    โžข Find โ€œaccessed ๐‘ฅ๐‘— nearest to ๐‘ฅ in either directionโ€

    o either the largest among all ๐‘ฅ๐‘— โ‰ค ๐‘ฅโ€ฆ

    o or the smallest among all ๐‘ฅ๐‘— โ‰ฅ ๐‘ฅ

    โžข If you take the largest ๐‘ฅ๐‘— โ‰ค ๐‘ฅ, start from there and keep going โ€œnextโ€ until you find ๐‘ฅ or go past its value

    โžข If you take the smallest ๐‘ฅ๐‘— โ‰ฅ ๐‘ฅ, start from there and keep going โ€œpreviousโ€ until you find ๐‘ฅ or go past its value

  • Searching in Sorted List

    373F20 - Nisarg Shah 49

    โ€ข Analysis sketch:โžข Suppose you find the largest ๐‘ฅ๐‘— โ‰ค ๐‘ฅ and keep going โ€œnextโ€

    โžข Let ๐‘ฅ๐‘– be smallest value โ‰ฅ ๐‘ฅ

    โžข Algorithm stops when it hits ๐‘ฅ๐‘–โžข Algorithm throws ๐‘› random โ€œdartsโ€ on the sorted list

    โžข Chernoff bound:

    o Expected distance of ๐‘ฅ๐‘– to the closest dart to its left is ๐‘‚ ๐‘›

    o Weโ€™ll assume this without proof!

    โžข Hence, the algorithm only does โ€œnextโ€ ๐‘‚ ๐‘› times in expectation

  • Searching in Sorted List

    373F20 - Nisarg Shah 50

    โ€ข Note:โžข We donโ€™t really require the list to be doubly linked. Just โ€œnextโ€

    pointer suffices if we have a pointer to the first element of the list (a.k.a. โ€œanchored listโ€).

    โ€ข This algorithm is optimal!

    โ€ข Theorem: No algorithm that always returns the correct answer can run in ๐‘œ ๐‘› expected time.โžข Can be proved using โ€œYaoโ€™s minimax principleโ€

    โžข Beyond the scope of the course, but this is a fundamental result with wide-ranging applications

  • Sublinear Geometric Algorithms

    373F20 - Nisarg Shah 51

    โ€ข Chazelle, Liu, and Magen [2003] proved the ฮ˜ ๐‘› bound for searching in a sorted linked list

    โžข Their main focus was to generalize these ideas to come up with sublinear algorithms for geometric problems

    โžข Polygon intersection: Given two convex polyhedra, check if they intersect.

    โžข Point location: Given a Delaunay triangulation (or Voronoi diagram) and a point, find the cell in which the point lies.

    โžข They provided optimal ๐‘‚ ๐‘› algorithms for both these problems.

  • 373F20 - Nisarg Shah 52

    Inexact algorithms, expected sublinear time

  • Estimating Avg Degree in Graph

    373F20 - Nisarg Shah 53

    โ€ข Input:โžข Undirected graph ๐บ with ๐‘› vertices

    โžข ๐‘‚ 1 access to the degree of any queried vertex

    โ€ข Output: โžข Estimate the average degree of all vertices

    โžข More precisely, we want to find a (2 + ๐œ–)-approximation in expected time ๐‘‚ ๐œ–โˆ’๐‘‚ 1 ๐‘›

    โ€ข Wait!โžข Isnโ€™t this equivalent to โ€œgiven an array of ๐‘› numbers between 1 and

    ๐‘› โˆ’ 1, estimate their averageโ€?

    โžข No! That requires ฮฉ(๐‘›) time for any constant approximation!

    o Consider an instance with constantly many ๐‘› โˆ’ 1โ€™s, and all other 1โ€™s: you may not discover any ๐‘› โˆ’ 1 until you query ฮฉ(๐‘›) numbers

  • Estimating Avg Degree in Graph

    373F20 - Nisarg Shah 54

    โ€ข Why are degree sequences more special?

    โ€ข Erdล‘sโ€“Gallai theorem:

    โžข ๐‘‘1 โ‰ฅ โ‹ฏ โ‰ฅ ๐‘‘๐‘› is a degree sequence iff their sum is even and ฯƒ๐‘–=1

    ๐‘˜ ๐‘‘๐‘– โ‰ค ๐‘˜ ๐‘˜ โˆ’ 1 + ฯƒ๐‘–=๐‘˜+1๐‘› ๐‘‘๐‘–

    โ€ข Intuitively, we will sample ๐‘‚ ๐‘› verticesโžข We may not discover the few high degree vertices but weโ€™ll find their

    neighbors and thus account for their edges anyway!

  • Estimating Avg Degree in Graph

    373F20 - Nisarg Shah 55

    โ€ข Algorithm:

    โžข Take ฮค8 ๐œ– random subsets ๐‘†๐‘– โŠ† ๐‘‰ with ๐‘†๐‘– = ๐‘‚๐‘›

    ๐œ–

    โžข Compute the average degree ๐‘‘๐‘†๐‘– in each ๐‘†๐‘–.

    โžข Return ๐‘‘ = min๐‘– ๐‘‘๐‘†๐‘–

    โ€ข Analysis beyond the scope of this course

    โžข This gets the approximation right with probability at least 5

    6

    โžข By repeating the experiment ฮฉ log ๐‘› times and reporting the median answer, we can get the approximation right with probability at least 1 โˆ’ 1/๐‘‚ ๐‘› and a bad approximation with the other 1/๐‘‚ ๐‘›probability cannot hurt much