Hammer's Blog

Covex hull

Graham Scan

pseudo code

sort by y-order; //$p_1, p_2, ..., p_n$
stack.push($p_1, p_2$);
for i = 3 to $n$ do
  while next $\angle next, top, $p_i$ != CCW
    stack.pop()
  stack.push($p_i$)
return stack

Analysis of Graham Scan

  1. Invariant $<p_1, … ,stack.top()>$ is convex
  2. 기울기 공식: $D = det\begin{vmatrix} 1 & p_x & p_y \ 1 & q_x & q_y \ 1 & r_x & r_y \end{vmatrix}$
  1. 정렬 이후 $O(n)$번의 스캔이 일어나며 반복 수행마다 $logn$의 시간 소요

Divide and Conquer

pseudo code

이미지1

Analysis of Divide and conquer

References

#Divide and Conquer #Algorithm