# hw6s - Cs445 Homework#6 Network Flow Computational Geometry...

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

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 0 be the first vertex of CH ( S ) in the Graham-scan algorithm. Let m denote the number of points other than p 0 that remain after step 2 of the algorithm. Note: m n - 1 .The three points p 0 , 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 = 0 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

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

View Full Document
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 ] . We set l = 1 , mid = floorleft n/ 2 floorright and r = n . Clearly at least one of the set of vertices ( V [ l ] , V [ next ( l )] , . . . V [ mid ]) , and ( V [ next ( mid )] , . . . V [ r ]) contains R . There are several cases that we need to check to find which set it is, depending which of the three vertices V [ l ] , V [ mid ] , V [ r ] are on the upper part of P , and which are on the lower part, and their x -coordinate.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern