hw6s - Cs445 — Homework #6 Network Flow, Computational...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Cs445 — Homework #6 Network Flow, Computational Geometry and Dynamic Programming Due: 5/3/2005 during class meeting. 1. Run the for line-sweep algorithm for finding if two segments intersect for the example in Figure 1. Answer: The solution appears in Figure 1. Lines { lscript 1 . . . lscript 8 } denote the event points. Below the line numbers, the sweep-line status is indicated. At lscript 8 , segments s 1 and s 5 become consecutive in the total order. Hence, an intersection is found and the algorithm returns TRUE. 2. In the Graham-scan algorithm for computing CH ( S ), what is the maximum number of pop operations that can be executed when the algorithm reaches the i ’th point ? Answer: Let p be the first vertex of CH ( S ) in the Graham-scan algorithm. Let m denote the number of points other than p that remain after step 2 of the algorithm. Note: m ≤ n- 1 .The three points p , p 1 and p m are never popped from the stack. Hence at most m- 2 pop operations can be performed in total. Let maxpop i denote the maximum number of pop operations that can be ex- ecuted when the algorithm reaches the i ’th point and pop i denote the actual number of pop operations performed when the algorithm reached the i ’th point. No pop operations are performed when i = 0 , 1 , 2 . Hence, maxpop i for different values of i where i takes on values { 3 . . . m } is :- pop i = when i = 0 , 1 , 2 maxpop i = i- 2- ∑ i- 1 j =2 pop j when i = { 3 . . . m } 3. Let V [1 ..n ] be an array containing the vertices { v 1 . . . v n } of a convex P , in a clockwise order. See figure 2. Assume that no edge of the polygon is vertical. 1 s 1 s 2 s 3 s 4 s 5 lscript 1 lscript 2 lscript 3 lscript 4 lscript 5 lscript 6 lscript 7 lscript 8 Figure 1: v 1 v 2 v 3 v 4 v 5 v 6 v 7 v 8 v 9 v 10 P Figure 2: Example: The rightmost point of P is v 3 Prove that the rightmost point of P is a vertex of P , and describes a function that receives as input pointers to the first and last elements of V , and returns as output the rightmost vertex of V (the vertex with the largest x-coordinate). Assume that V is already in memory, and you do need to spend time processing the whole array. The running time of the function is O (log n ). Answer: Basically we are using standard binary search, but there are a few saddle details that we need to consider. Let R denote the rightmost vertex of P . Since the vertices of P appear along V in a clockwise order, we can compare the x-coordinate of V [ i ] and V [ prev ( i )] and V [ next ( i )] and find whether V [ i ] is R , and if not, whether V [ i ] is on the upper part of P or the lower part. Here next ( i ) = i + 1 if i < n , and next ( n ) = 1 . prev ( i ) = i- 1 if i > 1 , and prev (1) = n . Let V [ i ] .x denote the x-coordinate of V [ i ] ....
View Full Document

This note was uploaded on 05/27/2008 for the course CS 445 taught by Professor Williams during the Spring '06 term at Arizona.

Page1 / 7

hw6s - Cs445 — Homework #6 Network Flow, Computational...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online