chapter 13 backward analysis
play

Chapter 13 Backward analysis NEW CS 473: Theory II, Fall 2015 - PDF document

Chapter 13 Backward analysis NEW CS 473: Theory II, Fall 2015 October 8, 2015 13.1 Some more probability 13.1.0.1 Some more probability Lemma 13.1.1. E 1 , . . . , E n : n events (not necessarily independent). Then,


  1. Chapter 13 Backward analysis NEW CS 473: Theory II, Fall 2015 October 8, 2015 13.1 Some more probability 13.1.0.1 Some more probability Lemma 13.1.1. E 1 , . . . , E n : n events (not necessarily independent). Then, � � � � � � � � � ∩ n Pr = Pr ∗ Pr E 2 | E 1 ∗ Pr � E 1 ∩ E 2 ∗ . . . i =1 E i E 1 E 3 � � � � ∗ Pr E n � E 1 ∩ . . . ∩ E n − 1 . � 13.2 Backward analysis 13.2.0.1 Backward analysis (A) P = � p 1 , . . . , p n � be a random ordering of n distinct numbers. (B) X i = 1 ⇐ ⇒ p i is smaller than p 1 , . . . , p i − 1 . (C) Lemma 13.2.1. Pr [ X i = 1] = 1 /i . 13.2.0.2 Proof... Lemma 13.2.2. Pr [ X i = 1] = 1 /i . Proof: (A) Fix elements appearing in set( P i ) = { s 1 , . . . , s i } . � � � (B) Pr p i = min( P i ) � set( P i ) = 1 /i . � � � Pr p i = min( P i ) � � � � = Pr p i = min( P i ) � set( P i ) = S Pr [ S ] � S ⊆ P , | S | = i 1 i Pr [ S ] = 1 � = i . S ⊆ P , | S | = i 1

  2. 13.2.1 # of times... 13.2.1.1 ...the minimum changes in a random permutation... Theorem 13.2.3. In a random permutation of n distinct numbers, the minimum of the prefix changes in expectation ln n + 1 times. Proof: (A) Y = � n i =1 X i . (B) E [ Y ] = E [ � n i =1 X i ] = � n i =1 E [ X i ] = � n i =1 1 /i ≤ ln n + 1. 13.2.1.2 High probability Lemma 13.2.4. Π = π 1 . . . π n : random permutation of { 1 , . . . , n } . X i : indicator variable if π i is the smallest number in { π 1 , . . . , π i } , for ∀ i . Then Z = � n i =1 X i = O (log n ) ., w.h.p. (i.e., ≥ 1 − 1 /n O (1) ). proof (A) E i : the event that X i = 1, for i = 1 , . . . , n . (B) Claim: E 1 , . . . , E n are independent. (C) Generate permutation: Randomly pick a permutation of the given numbers, set first number to be π n . (D) Next, pick a random permutation of the remaining numbers and set the first number as π n − 1 in output permutation. (E) Repeat this process till we generate the whole permutation. 13.2.1.3 Proof continued... � � � � � (A) For any indices 1 ≤ i 1 < i 2 < . . . < i k ≤ n , and observe that Pr E i k � E i 1 ∩ . . . ∩ E i k − 1 = Pr E i k , � (B) ..because E i 1 determined after all E i 2 , . . . , E k . � � � � � � � � (C) By induction: Pr E i 1 ∩ E i 2 ∩ . . . ∩ E i k = Pr � E i 2 ∩ . . . ∩ E i k Pr [ E i 2 ∩ . . . ∩ E i k ]= Pr Pr E i 2 ∩ E i 1 E i 1 � = � k = � k � � � 1 E i 3 ∩ . . . ∩ E i k j =1 Pr i j . E i j j =1 ⇒ variables X 1 , . . . , X n are independent. (D) = (E) Result readily follows from Chernoff’s inequality. 2

  3. 3

  4. 13.3 Closest pair in linear time 13.3.0.1 Finding the closest pair of points 4

  5. 13.3.0.2 Grids... (1,2) (0,2) (0,2) (2,2) (2,1) (0 , 1) (0 , 1) (1,1) (A) r : Side length of grid cell. (B) Grid cell IDed by pair of integers. (C) Constant time to determine a point p ’s grid cell id: id ( p ) = ( ⌊ p x /r ⌋ , ⌊ p y /r ⌋ ) r (D) Limited use of the floor function (but no word pack- (0 , 0) (1,0) (2,0) (0 , 0) ing tricks). (E) Use hashing on (grid) points. r (F) Store points in grid... ...in linear time. 13.3.0.3 Storing point set in grid/hash-table... r Hashing: (A) Non-empty grid cells (B) For non-empty grid cell: List of points in it. (C) For a grid cell: Its neighboring cells. 13.3.0.4 Closet pair in a square Lemma 13.3.1. Let P be a set of points α contained inside a square � , such that the p sidelength of � is α = CP ( P ) . Then | P | ≤ 4 . 5

  6. Proof: Partition � into four equal squares � 1 , . . . , � 4 . √ Each square diameter 2 α/ 2 < α . ... contain at most one point of P ; that is, the disk of radius α centered at a point p ∈ P completely covers the subsquare containing it; see the figure on the right. P can have four points if it is the four corners of � . 13.3.0.5 Verify closet pair Lemma 13.3.2. P : set of n points in the plane. α : distance. Verify in linear time whether CP ( P ) < α , CP ( P ) = α , or CP ( P ) > α . proof Indeed, store the points of P in the grid G α . For every non-empty grid cell, we maintain a linked list of the points inside it. Thus, adding a new point p takes constant time. Specifically, compute id( p ), check if id( p ) already appears in the hash table, if not, create a new linked list for the cell with this ID number, and store p in it. If a linked list already exists for id( p ), just add p to it. This takes O ( n ) time overall. Now, if any grid cell in G α ( P ) contains more than, say, 4 points of P , then it must be that the CP ( P ) < α , by previous lemma. 13.3.0.6 Proof continued (A) When insert a point p : fetch all the points of P in cluster of P (B) Takes constant time. (C) If there is a point closer to p than α that was D p already inserted, then it must be stored in one of these 9 cells. α (D) Now, each one of those cells must contain at most 4 points of P by prev lemma. (E) Otherwise, already stopped since CP ( · ) < α . 13.3.0.7 Proof continued (A) S set of all points in cluster. (B) | S | ≤ 9 · 4 = O (1). (C) Compute closest point to p in S . O (1) time. D p (D) If d ( p , S ) < α , we stop; otherwise, continue to next point. α (E) Correctness: ‘ CP ( P ) < α ’ returned only if such pair found. 6

  7. 13.3.0.8 Proof continued (A) Assume p and q : realizing closest pair. (B) � p − q � = CP ( P ) < α . D (C) When later point (say p ) inserted, the set S p would contain q . α (D) algorithm would stop and return ‘ CP ( P ) < α ’. (E) 13.3.0.9 New algorithm (A) Pick a random permutation of the points of P . (B) � p 1 , . . . , p n � be this permutation. (C) α 2 = � p 1 − p 2 � . (D) Insert points into the closet-pair distance verifying data-structure. (E) α i : the closest pair distance in the set P i = { p 1 , . . . , p i } , for i = 2 , . . . , n . (F) i th iteration: (A) if α i = α i − 1 . insertion takes constant time. (B) If α i < α i − 1 then: know new closest pair distance α i . (C) rebuild the grid, and reinsert the i points of P i from scratch into the grid G α i . Takes O ( i ) time. (G) Returns the number α n and points realizing it. 13.3.0.10 Weak analysis... Lemma 13.3.3. Let t be the number of different values in the sequence α 2 , α 3 , . . . , α n . Then E [ t ] = O (log n ) . As such, in expectation, the above algorithm rebuilds the grid O (log n ) times. proof (A) X i = 1 ⇐ ⇒ α i < α i − 1 . (B) E [ X i ] = Pr [ X i = 1] and t = � n i =3 X i . (C) Pr [ X i = 1] = Pr [ α i < α i − 1 ]. (D) Backward analysis. Fix P i . (E) q ∈ P i is critical if CP ( P i \ { q } ) > CP ( P i ). (F) No critical points, then α i − 1 = α i and then Pr [ X i = 1] = 0. 13.3.0.11 Proof continued... (A) If one critical point, then Pr [ X i = 1] = 1 /i . (B) Assume two critical points and let p , q be this unique pair of points of P i realizing CP ( P i ). (C) α i < α i − 1 ⇐ ⇒ p or q is p i . (D) Pr [ X i = 1] = 2 /i . (E) Cannot be more than two critical points. (F) Linearity of expectations: E [ t ] = E [ � n i =3 X i ] = � n i =3 E [ X i ] ≤ � n i =3 2 /i = O (log n ). (G) 7

  8. 13.3.0.12 Expected linear time analysis... Theorem 13.3.4. P : set of n points in the plane. Compute the closest pair of P in expected linear time. Proof: (A) X i = 1 ⇐ ⇒ α i � = α i − 1 . (B) Running time is proportional to R = 1 + � n i =3 (1 + X i · i ). (C) E [ R ] = E [1 + � n i =3 (1 + X i · i )] ≤ n + � n i =3 E [ X i ] · i ≤ n + � n i =3 i · Pr [ X i = 1] ≤ n + � n i =3 i · 2 i ≤ 3 n, by linearity of expectation and since E [ X i ] = Pr [ X i = 1] ≤ 2 /i . (D) Expected running time of the algorithm is O ( E [ R ]) = O ( n ). 13.4 Computing nets 13.4.1 Nets 13.4.1.1 The Main Tool r -net N ⊆ P is an r -net if • Every point in P has distance < r to a point in N • For any two p , q ∈ N , we have d ( p , q ) ≥ r . 13.4.1.2 Computing an r-net 8

  9. r 9

  10. 13.4.2 Application of Grids: Computing nets 13.4.2.1 ...in linear time Repeatedly: (1) Pick any unmarked point. (2) Mark all neighbors in distance < r . In an r -grid (A) Neighbors in distance < r , are in neighboring cells. (B) Neighboring Cells found in O (1) time. (C) Cells contain lists of points. 13.5 Computing a good ordering of the vertices of a graph 13.5.0.1 Input (A) G = ( V , E ): edge-weighted. (B) n vertices and m edges. (C) Task: compute an ordering π = � π 1 , . . . , π n � of vertices. (D) ∀ v ∈ V L v : π i ∈ � L v , ⇐ ⇒ π i closet vertex to v in prefix � π 1 , . . . , π i � . (E) Example: Streaming scenario - install servers in a network. .... every client in t network needs to know its closest server. (F) ... client needs to maintain its current closest server. (G) How min total size of lists? L = � v ∈ V | L v | . 13.5.0.2 Algorithm (A) π 1 , . . . , π n : random permutation of V of G . (B) ∀ v ∈ V δ ( v ) = + ∞ . (C) For i = 1 to n do: (A) δ ( π i ) to 0, (B) start Dijkstra from the i th vertex π i . (C) Dijkstra propagates to u only if improves current distance. ⇒ d G ( π i , u ) < δ ′ ( u ) (D) Update δ ( u ) to d G ( π i , u ) ⇐ δ ′ ( u ): value before this iteration started. (E) If δ ( u ) updated: add π i to L u . 13.5.1 Analysis 13.5.1.1 Performance Lemma 13.5.1. Algorithm computes a permutation π , such that: � � (A) E |L| = O ( n log n ) . � � (B) Expected running time O ( n log n + m ) log n . (C) n = | V ( G ) | and m = | E ( G ) | . 10

Recommend


More recommend