Backwards Analysis Gerth Stlting Brodal Pre-talent track activity - - PowerPoint PPT Presentation

backwards analysis
SMART_READER_LITE
LIVE PREVIEW

Backwards Analysis Gerth Stlting Brodal Pre-talent track activity - - PowerPoint PPT Presentation

Backwards Analysis Gerth Stlting Brodal Pre-talent track activity in Algorithms, Department of Computer Science, Aarhus University, February 19, 2019 Pareto optimal / non-dominated points / skyline No points Pareto optimal Dominated points


slide-1
SLIDE 1

Backwards Analysis

Gerth Stølting Brodal

Pre-talent track activity in Algorithms, Department of Computer Science, Aarhus University, February 19, 2019

slide-2
SLIDE 2

Dominated points No points

Pareto optimal / non-dominated points / skyline

Skyline Vilfredo Pareto (1848–1923) Pareto optimal

slide-3
SLIDE 3

Exercis ise 1 (skyline construction)

Skyline

Given n points (x1, y1), ..., (xn, yn) in R2

  • Give an algorithm for computing the points on the skyline ?
  • What is the running time of your algorithm ?

skyline

slide-4
SLIDE 4

Problem – expected skyline siz ize ? ?

Skyline size

  • Consider n points (x1, y1), ..., (xn, yn) in R2
  • Each xi and yi is selected independently

and uniformly at random from [0, 1]

  • What is the expected skyline size ?

1 1

slide-5
SLIDE 5

Exercis ise 2 (dependent points)

Skyline size

  • Describe an algorithm for generating n

distinct points (x1, y1), ..., (xn, yn) in R2

  • Each xi and yi is selected uniformly at

random from [0, 1]

  • The points are not independent

1 1

slide-6
SLIDE 6

Generating random points

Assume the points are generated by the following algorithm 1) Generate n random x-values x1, ..., xn 2) sort the x-values in decreasing order 3) for decreasing xi generate random yi (xi, yi) is a skyline point ⟺ yi = max(y1, ..., yi) Prob[(xi, yi) skyline point] = 1 i since y1, ..., yi independt and the same distribution, all permutations are equally likely, i.e. probability yi to be largest among i values is 1/i

Skyline size 1 1 (xi, yi) (x1, y1)

slide-7
SLIDE 7

Expected skyline siz ize

Stochastic variable: Xi = ቊ1 if point i on skyline

  • therwise

E[|skyline|] = E[X1 + ∙∙∙ + Xn] = E[X1] + ∙∙∙ + E[Xn] = Σi Prob[(xi, yi) skyline point] = 1

1 + 1 2 + ∙∙∙ + 1 n

= σi=1..n

1 i

(harmonic number Hn) ≤ ln n + 1

Skyline size 1 1 (xi, yi) (x1, y1)

slide-8
SLIDE 8

n-th Harmonic number Hn = 1/1 + 1/2 + 1/3 +∙∙∙+ 1/n = 1/i

n i = 1

Σ

1/n n 1 2 3 4 5 1/1 1/2 1/3 1/4 1/n

1/x dx = [ ln x ] = ln n – ln 1 = ln n

n 1 n 1

Hn – 1   Hn – 1/n ln n + 1/n  Hn  ln n + 1

Harmonic numbers

slide-9
SLIDE 9

Exercis ise 3 (divide-and-conquer skyline)

Skyline

Consider the following algorithm

  • Find the topmost point p in O(n) time
  • recurse on points to the right of p

Show that the expected running time is O(n)

1 1 p

slide-10
SLIDE 10

QuickSort – a a randomized sorting alg lgorithm

Quicksort(x1, ..., xn)

  • Pick a random pivot element xi
  • Partition remaining elements: S smaller than xi, and L larger than xi
  • Recursively sort S and L

QuickSort

7 4 15 12 8 11 3 5 1 14 6 7 4 3 5 1 6 8 15 12 11 14 3 1 4 7 5 6 11 15 12 14 1 3 5 6 7 12 14 15 3 5 6 12 15 6

slide-11
SLIDE 11

QuickSort – analy lysis I

Alternative Quicksort

  • Consider a random permutation π of the input, such that

xπ(1) is the first pivot, then xπ(2), xπ(3), .... Observations

  • Changes the order unsorted sublists are partitioned, but the

pivots are still selected uniformly among the elements

  • xi and xj are compared if and only xi or xj is selected as a

pivot before any element in the sorted list between xi and xj

QuickSort

xj xi

  • utput
slide-12
SLIDE 12

QuickSort – analy lysis II II

E[comparisons by quicksort] = E[Σi<j cost of comparing xi and xj] = Σi<j E[cost of comparing xi and xj] = Σi<j

2 |r j − r(i)| + 1 where r(i) = position of xi in output

= Σ1≤p<q≤n

2 q − p + 1

≤ 2n∙Σ2≤d≤n

1 d

≤ 2n∙((ln n + 1) – 1) = 2n∙ln n

QuickSort

xj xi

r(j) r(i) q p d

  • utput
slide-13
SLIDE 13

Exercis ise 4 (random search trees)

Construct a unbalanced binary search tree for n numbers x1 <∙∙∙< xn by inserting the numbers in random order

  • What is the probability that xj is an ancestor of xi ?
  • What is the expected depth of a node xi ?

15 8 17 13 10 3 5

Random search trees

Insert: 15, 8, 17, 13, 3, 5, 10

slide-14
SLIDE 14

Convex hull

Convex hull = smallest polygon enclosing all points

Convex hull

slide-15
SLIDE 15

Exercis ise 5: Convex hull

Convex hull

Give an O(n∙log n) worst-case algorithm finding the Convex Hull

slide-16
SLIDE 16

Convex hull – randomized in incremental

1) Let p1, ..., pn be a random permutation of the points 2) Compute convex hull of {p1, p2, p3} 3) c = (p1 + p2 + p3) / 3 4) for i = 4 to n insert pi and construct Hi from Hi-1 :

if pi inside Hi-1 skip, otherwise insert pi in Hi-1 and delete chain inside

Convex hull

c p1 p2 p3 c H3 pi Hi-1

slide-17
SLIDE 17

Convex hull – in inserting pi

Convex hull

c pi e Hi-1

slide-18
SLIDE 18

Convex hull – in inserting pi

Convex hull

c pi e Hi-1

How to find e for pi ? store set of points with e and reference to e from pi

slide-19
SLIDE 19
  • Each point inserted / deleted / inside at most once in convex hull
  • E[# point-edge updates]

= E[Σ4≤i≤n Σp p updated on insertion i] = Σ4≤i≤n Σp E[p updated on insertion i] ≤ Σ4≤i≤n Σp

2 i − 3

≤ 2n∙(ln n + 1) since p only updated on insertion i if pi is u or v

  • Total expected time O(n∙log n)

Convex hull - analy lysis

Convex hull

c Hi e p u v

slide-20
SLIDE 20

Bin inary ry search - but forgot to sort the array...

(a debugg gging case)

Binary searching unsorted array

2 3 41 31 11 13 7 17 23 47 19 43 5 29 37

2 3 41 11 23 19 43 5 29 37 31 7 47 13 17

useful useful useful not reachable

find(41)

How many cells can ever be reached by a binary search ?

slide-21
SLIDE 21

Reachable nodes – analy lysis

Pr[ vi useful ] = |Li| / Σj|Lj| E[ # useful nodes at level ] = Σi ( |Li| / Σj|Lj| ) = 1 E[ # useful nodes in tree ] = height - 1 E[ # reachable nodes in tree ] ≤ height2 = O(log2 n)

v1 v4 v3 v2 43 31 17

useful useful

]-∞,17[ ]17,43[ ∅ ]43,∞[ L1 = { 2,3,4,5,11 } L2 = ∅ L3 = { 19,23,29,37,41 } L4 = { 47 }

# useful nodes ?

Binary searching unsorted array

slide-22
SLIDE 22

Clo losest pair ir

Given n points, find pair (p, q) with minimum distance Algorithm (idea)

  • permute points randomly  p1, p2, ..., pn
  • for i = 2..n compute Δi = distance between closest pair for p1, ..., pi

Observation

  • Pr[Δi < Δi-1] ≤ 2

i

since minimum distance can only decrease if pi is defining Δi

p q

Closest pair

slide-23
SLIDE 23

Clo losest pair ir – grid cell lls

Δi-1

  • Construct grid cells with side-length Δi-1
  • Point (x, y) in cell ( x/Δi−1 , y/Δi−1 )
  • ≤ 4 points in cell if all pairwise distances ≥ Δi-1
  • Neighbors of pi within distance Δi-1 are in ≤ 9 cells
  • Store non-empty cells in a hash tabel (using randomization)
  • Rebuild grid whenever Δi decreases

Analysis

  • E[rebuild cost] = E[Σ3≤i≤n rebuild cost inserting pi]

= Σ3≤i≤n E[rebuild cost inserting pi] ≤ Σ3≤i≤n

2 i i ≤ 2n

  • Total expected time O(n)

pi

Closest pair

slide-24
SLIDE 24

Handin (Treaps)

A treap is a binary search tree with a random priority assigned to each element when inserted (in the example elements are white and priorities yellow). A left-to-right inorder traversal gives the elements in sorted order, whereas the priorities satisfy heap order, i.e. priorities increase along a leaf-to-root path. a) Argue that an arbitrary element in a treap of size n has expected depth O(log n) b) Describe how to insert an element into a treap and give running time

13

0.5

21

0.4

3

0.1

11

0.3

7

0.9

8

0.1

Treaps

slide-25
SLIDE 25

References

  • Raimund Seidel, Backwards Analysis of Randomized Geometric Algorithms, in Pach J. (eds) New

Trends in Discrete and Computational Geometry. Algorithms and Combinatorics, vol 10, 37-67. Springer, Berlin, Heidelberg 1993. DOI: 10.1007/978-3-642-58043-7_3 (public available at CiteSeerX). [Chapters 4-5]

  • Sariel Har-Peled, Backwards analysis, lecture notes, 2014. sarielhp.org. [Chapters 39.1-39.3]
  • Raimund Seidel and Cecilia R. Aragon, Randomized search trees, Algorithmica, 16(4–5), 464–497,
  • 1996. DOI 10.1007/BF01940876.
  • David R. Karger, Philip N. Klein, Robert E. Tarjan, A randomized linear-time algorithm to find

minimum spanning trees, Journal of the ACM, 42(2), 321-328, 1995. DOI 10.1145/201019.201022.

  • Timothy M. Chan, Backwards analysis of the Karger-Klein-Tarjan algorithm for minimum spanning

trees, Information Processing Letters, 67(6), 303-304, 1998. DOI 10.1016/S0020-0190(98)00129-X.

References