190 likes | 271 Views
CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego. Trees with at most 4 edges. A useful fact about trees. Any tree on n vertices contains a vertex v whose removal separates the remaining graph into two parts, one of which is of sizes
E N D
CSE 202 Divide-and-conquer algorithms Fan Chung Graham UC San Diego
A useful fact about trees Any tree on n vertices contains a vertex v whose removal separates the remaining graph into two parts, one of which is of sizes at most n/2 and the other is at most 2n/3.
A useful fact about trees Any tree on n vertices contains a vertex v whose removal separates the remaining graph into two parts, one of which is of sizes at most n/2 and the other is at most 2n/3. Try to write a proof for this!
A planar graph is a graph that can be drawn in the plane without crossings.
A planar graph is a graph that can be drawn in the plane without any crossing. Are these planar graphs?
A planar graph is a graph that can be drawn in the plane without any crossing. Are these planar graphs?
A useful fact about planar graphs Any planar graph on n vertices contains vertices whose removal separates the remaining graph into two parts, one of which is of sizes at most n/2 and the other is at most 2n/3. Tarjan and Lipton, 1977
Merge-and-Count(A,B) algorithm Input: sorted Output: a sorted list L, count of # inversions in Initially, a pointer at first element of A, a pointer at first element of B, size of A, also, set count =0,and While if increase count by size of A, move the pointer of B by 1, else, move the pointer of A by 1, decrease size by 1, endif endwhile to L append smaller of
Implementing sort-and-count algorithm Running time O(n log n)