COMP 5045 – Assignment 1

As a first step go to the third page and read the section: Advice on how to do
the home work.
1. Let S be a set of n points in the plane sorted with respect to their ycoordinate from bottom to top. Give an algorithm that computes the
convex hull of S in O(n) time. Argue its time complexity. [10 points]
2. You are given two x-monotone polygonal chains P and Q. Prove that
the number of times P and Q can intersect is O(n), where n is the total
number of vertices of P and Q, see Figure 1(a). [10 points]
3. Let ` be a line in the plane and let p be a point. The orthogonal projection
of p onto ` is the point q on ` such that the line segment (p, q) is orthogonal
to `, as shown in Fig. 1(b).
(a) Given a convex polygon P and a point q within P prove that q has
an orthogonal projection onto the perimeter of P . [6 points]
(b) What if P is not convex? Prove or disprove the statement. [4 points]

P

p

q

Q
`
(a)

(b)

Figure 1: (a) Two x-monotone paths P and Q. (b) Illustrating the orthogonal
projection q of p onto `.

4. Let R be a set of n red segments in the plane and let B be a set of m
blue segments in the plane. Design an algorithm that counts the number
of intersections between the segments in R and the segments in B. Prove
the running time, space requirement and correctness of your algorithm.
For full points the algorithm should use O((n + m) log(n + m)) time and
O(n + m) space. [10 points]

1

Define the fatness of S to be the largest Euclidean distance between two points in S. [2 points] (b) Consider the edge e connecting the highest point in H1 with the highest point in H2 . Describe an efficient algorithm for determining the fatness of S. Prove the running time. Determine in O(n + m) expected time if there exists a line ` such that all the cats are on one side of ` and all the dogs are on the other side of `. For full points the algorithm should use O((n + m) log(n + m)) time and O(n + m) space. Suppose you are given a set S of n points in the plane. [2 points] (d) Give a correct implementation of step 4. H. Step 4: From H1 and H2 compute the convex hull H of the entire point set. Will the edge e be an edge in H? Prove your answer. Step 1: Sort the points in S by increasing x-coordinate. Step 3: Recursively compute the convex hull of the right half of the point set. The resulting convex hull is denoted H2 . Step 2: Recursively compute the convex hull of the left half of the point set. Design an algorithm that finds the smallest area ∆(s. What is the running time of the algorithm? Prove your time bound. Prove the running time. p) the triangle defined by s as its base and p as its opposite corner. [4 points] 6. For full points the algorithm should use O(n log n) time and O(n) space. space requirement and correctness of your algorithm. Recall that the area of a triangle is 21 × base × height. (a) Assume that step 4 can be implemented in time O(n). of the entire set? Prove your answer. For a segment s ∈ S and a point p ∈ P denote by ∆(s. [10 points] 8. Let S be a set of n vertical segments and let P be a set of m points in the plane.5. Let C be a set of n cats and let D be a set of m dogs modelled as points in the plane. Prove the correctness and the running time of your algorithm. Can any of these points be in the convex hull. that runs in O(n) time. p) for all s ∈ S and p ∈ P . [10 points] 2 . The resulting convex hull is denoted H1 . Prove the time complexity and the correctness of your algorithm. [2 points] (c) Consider the points clockwise along H1 between the highest point of H1 to the lowest point of H1 . space requirement and correctness of your algorithm. [10 points] 7. Consider the following algorithm to compute the convex hull of a set S of n points in the plane.

then you also have to explain your code and your ideas. scientific papers. the algorithms does not have to be given as (pseudo-)code. then we will give you marks only for ”your worst answer”. • When giving answers to questions. and after that you might want to develop and elaborate on details. the internet.. hashing does not guarantee anything in the worst case. • If you do give (pseudo-)code. the more points we can give you. • It might help you (and us) if you briefly describe your general idea. we always would like you to prove/ explain/motivate your answers. Hence... and as it is typical for an algorithms course. 3 . If you give multiple answers. as this indicates how well you understood the question. we cannot give you points for it. we always ask about worst-case analysis. • Unless otherwise stated. • Some of the questions are very easy (with the help of the lecture notes or book). • If you use further resources (books. worst case running times etc. the faster your algorithm.) to formulate your answers. (for example. • When giving an algorithm as an answer. You can use the material presented in the lecture or book (without proving it). If we don’t see/understand your general idea. You do not need to write more than necessary (see comment above).Advice on how to do the home work • Be careful with giving multiple or alternative answers. we are interested in the most efficient algorithms. then add references to your sources. • As done in the lecture. in general).