阅读材料

课堂笔记

Convex Hull and Sorting

convex hull algorithms: O(nlogn)O(n\log n).

can we do better?

convex hull of points is equivalent to sorted numbers.

O(nlogn)O(n\log n) worst-case is optimal.

fewer than n points on the hull

O(nlogh)O(n\log h)?

Marriage Before Conquest

MbC(P:l,r): find Upper Hull of P from x-coordinates l to r

  1. find median x-coordinate xmx_m. partition into Pl,PrP_l,P_r. O(n)O(n) times
  2. find the bridge, uv, over xmx_m.
  3. remove the points below the bridge. O(n)O(n)
  4. recurse: MbC(Pl:l,ux)MbC(P_l:l,u_x) & MbC(Pr:vx,r)MbC(P_r:v_x,r) f(n2)+f(n2)f(\frac{n}{2})+f(\frac{n}{2})

if step 2 can be done in linear time, the total time is O(nlogh)O(n\log h).

How to find bridges

finding a bridge is equivalent to finding a line Y=aX+bY=aX+b that:

  • passes above all the points
  • has the lowest intersection point with the separating line (the lowest point that is not inside the convex hull)

find aa and bb s.t.:

  • yiaxi+by_i\le ax_i+b for every input point (xi,yi)(x_i,y_i)
  • ym=axm+by_m=ax_m+b is minimized

Linear Programming

unknowns: x1,,xdx_1,\cdots,x_d

minimize: c1x1+c2x2++cdxdc_1x_1+c_2x_2+\cdots+c_dx_d

s.t.

a1,1x1+a1,2x2++a1,dxdb1a2,1x1+a2,2x2++a2,dxdb2an,1x1+an,2x2++an,dxdbna_{1,1}x_1+a_{1,2}x_2+\cdots+a_{1,d}x_d\le b_1\\ a_{2,1}x_1+a_{2,2}x_2+\cdots+a_{2,d}x_d\le b_2\\ \cdots\cdots\\ a_{n,1}x_1+a_{n,2}x_2+\cdots+a_{n,d}x_d\le b_n\\

a\mathbf a, b\mathbf b, c\mathbf c are given as input.

dd dimensions

There a and b are unknown.

can be solved in O(n)O(n) time on average.

1D Linear Programming

unknown x1x_1

minimize c1x1c_1x_1 s.t. ai,1x1bia_{i,1}x_1\le b_i for i in 1 to n

find feasible region

possible cases: feasible, infeasible or unbounded.

O(n)O(n) running time

2D Linear Programming

unknown x1,x2x_1,x_2

minimize c1x1+c2x2c_1x_1+c_2x_2 s.t. ai,1x1+ai,2x2bia_{i,1}x_1+a_{i,2}x_2\le b_i for i in 1 to n

假设一些直线找到了一个可行区域

现在就只需要平移c1x1+c2x2=Vc_1x_1+c_2x_2=V 这条直线,以找到最小值。

  1. initialize vv.
  2. for i=1 to n
    1. if constraint i does not violate v: do nothing
    2. else solve 1D Linear programming with constraints 1 to i-1 on boundary of constraint i

step 2.2 might run n times O(n2)O(n^2) time in total.

A randomized incremental algorithm

  1. initialize v
  2. randomly relabel (shuffle) constraints
  3. for i = 1 to n
    1. if constraint i does not violate v: do nothing

    2. else solve 1D Linear Programming with constraints 1 to i-1 on boundary of constraint i

      意思就是新增的这个约束 i 对应的直线,把 x2 解出来,代入到前面 1 到 i-1 中的 x2,可以得到一个一维的线性规划问题。

improves from O(n2)O(n^2)% to O(n)O(n) time on average.

backward analysis (a claim): the probability that step 3.2 runs during the i-th iteration of the for loop is 2i\le\frac{2}{i}

expected running time:

E[i=1nRunning Time of ith Iteration]=i=1nE[Running Time of the ith Iteration]=i=1n(Pr[Step 3.2 runs at the ith Iteration]O(i)+O(1))=i=1n(2iO(i)+O(1))=i=1nO(1)=O(n)\mathbb E[\sum_{i=1}^nRunning\ Time\ of\ i-th\ Iteration]\\ =\sum_{i=1}^n\mathbb E[Running\ Time\ of\ the\ i-th\ Iteration]\\ =\sum_{i=1}^n(\Pr[Step\ 3.2\ runs\ at\ the\ i-th\ Iteration]\cdot O(i)+O(1))\\ =\sum_{i=1}^n(\frac{2}{i}\cdot O(i)+O(1))=\sum_{i=1}^nO(1)\\ =O(n)

how to shuffle?

Place i in a random non-empty spot for i = 1 to n

fill i-th spot randomly for i = 1 to n

fill i-th spot randomly from i = n to 1

To proof the claim:

consider the step 3.2

every constraint is a line, we have n of them. c1,,cnc_1,\cdots,c_n.

we have n positions in our shuffle.

the line is placed randomly in these n positions.

then the probability of entering 3.2:

  • Probability entering 3.2 at i=ni=n is: 2n\frac{2}{n}, because only two lines determin final result. since the order of lines are shuffled, the probability of n-th line is one of the two determin line is 2n\frac{2}{n}.
  • consider feasible region, the optimal solution is adjacent to 2 constraints c1,c2c_1,c_2. for i-th line probability would be 2i\frac{2}{i}

Chan’s Algortihm

陈氏算法,计算凸包的一种快速算法,时间复杂度 O(nlogh)O(n\log h)

预设一个凸包上的点的个数 h22ih\le2^{2^i}. ii11 开始尝试。

对每一个 i:

  • 将当前所有点分成 nh\frac{n}{h} 份,分别用 graham scan 计算凸包,这一步的时间复杂度为 O(hlogh)O(h\log h)。计算 nh\frac{n}{h} 次,所以总的时间复杂度为 O(nlogh)O(n\log h)

  • 从这些凸包上 x 坐标最小的点开始,找到这 nh\frac{n}{h} 个凸包合并的上凸包。就是对当前的点,找到通过分别二分查找 O(logh)O(\log h)nh\frac{n}{h} 个子凸包上和当前点连线正切值最小的点。这一步是 O(nhlogh)O(\frac{n}{h}\log h).

    因为假设凸包点数的上界是 h,最多要找 h 次,所以找到这些子凸包的公共上凸包的总时间为 O(nlogh)O(n\log h)

    如果假设正确,那么整个算法的时间复杂度为 O(nlogh)O(n\log h)

  • 如果算法错误,i++,并继续尝试计算。

    假设最终凸包上的点数为 hh,那么最多测试 loglogh\log\log h 次。

    所以总的时间复杂度为

    i=1logloghO(nlog(22i))=i=1logloghO(n2i)=O(n2loglogh)=O(nlogh)\sum_{i=1}^{\log\log h}O(n\log(2^{2^i}))\\ =\sum_{i=1}^{\log\log h}O(n2^i)=O(n2^{\log\log h})=O(n\log h)

妙啊!