Docsity

CS 373: Combinatorial Algorithms Homework 5, Fall 2000, Assignments of Computer Science

Toggle sidebar
bg1
CS 373: Combinatorial Algorithms, Fall 2000
Homework 1 (due November 16, 2000 at midnight)
Name:
Net ID: Alias: U 3
/
41
Name:
Net ID: Alias: U 3
/
41
Name:
Net ID: Alias: U 3
/
41
Starting with Homework 1, homeworks may be done in teams of up to three people. Each team
turns in just one solution, and every member of a team gets the same grade. Since 1-unit graduate
students are required to solve problems that are worth extra credit for other students, 1-unit grad
students may not be on the same team as 3/4-unit grad students or undergraduates.
Neatly print your name(s), NetID(s), and the alias(es) you used for Homework 0 in the boxes
above. Please also tell us whether you are an undergraduate, 3/4-unit grad student, or 1-unit grad
student by circling U, 3
/
4, or 1, respectively. Staple this sheet to the top of your homework.
Required Problems
1. Give an O(n2log n)algorithm to determine whether any three points of a set of npoints are
collinear. Assume two dimensions and exact arithmetic.
2. We are given an array of nbits, and we want to determine if it contains two consecutive 1
bits. Obviously, we can check every bit, but is this always necessary?
(a) (4 pts) Show that when nmod 3 = 0 or 2, we must examine every bit in the array.
that is, give an adversary strategy that forces any algorithm to examine every bit when
n= 2,3,5,6,8,9,....
(b) (4 pts) Show that when n= 3k+ 1, we only have to examine n−1bits. That is, describe
an algorithm that finds two consecutive 1s or correctly reports that there are none after
examining at most n−1bits, when n= 1,4,7,10,....
(c) (2 pts) How many n-bit strings are there with two consecutive ones? For which n is this
number even or odd?
pf3
pf4
pf5

Partial preview of the text

Download CS 373: Combinatorial Algorithms Homework 5, Fall 2000 and more Assignments Computer Science in PDF only on Docsity!

CS 373: Combinatorial Algorithms, Fall 2000

Homework 1 (due November 16, 2000 at midnight)

Name:

Net ID: Alias: U

Name:

Net ID: Alias: U

Name:

Net ID: Alias: U 3 / 4 1

Starting with Homework 1, homeworks may be done in teams of up to three people. Each team turns in just one solution, and every member of a team gets the same grade. Since 1-unit graduate students are required to solve problems that are worth extra credit for other students, 1-unit grad students may not be on the same team as 3/4-unit grad students or undergraduates.

Neatly print your name(s), NetID(s), and the alias(es) you used for Homework 0 in the boxes above. Please also tell us whether you are an undergraduate, 3/4-unit grad student, or 1-unit grad student by circling U, 3 / 4 , or 1, respectively. Staple this sheet to the top of your homework.

Required Problems

  1. Give an O(n^2 log n) algorithm to determine whether any three points of a set of n points are collinear. Assume two dimensions and exact arithmetic.
  2. We are given an array of n bits, and we want to determine if it contains two consecutive 1 bits. Obviously, we can check every bit, but is this always necessary?

(a) (4 pts) Show that when n mod 3 = 0 or 2, we must examine every bit in the array. that is, give an adversary strategy that forces any algorithm to examine every bit when n = 2, 3 , 5 , 6 , 8 , 9 ,.... (b) (4 pts) Show that when n = 3k + 1, we only have to examine n − 1 bits. That is, describe an algorithm that finds two consecutive 1s or correctly reports that there are none after examining at most n − 1 bits, when n = 1, 4 , 7 , 10 ,.... (c) (2 pts) How many n-bit strings are there with two consecutive ones? For which n is this number even or odd?

  1. You are given a set of points in the plane. A point is maximal if there is no other point both both above and to the right. The subset of maximal points of points then forms a staircase.

The staircase of a set of points. Maximal points are black.

(a) (0 pts) Prove that maximal points are not necessarily on the convex hull. (b) (6 pts) Give an O(n log n) algorithm to find the maximal points. (c) (4 pts) Assume that points are chosen uniformly at random within a rectangle. What is the average number of maximal points? Justify. Hint: you will be able to give an exact answer rather than just asymptotics. You have seen the same analysis before.

  1. Given a set Q of points in the plane, define the convex layers of Q inductively as follows: The first convex layer of Q is just the convex hull of Q. For all i > 1 , the ith convex layer is the convex hull of Q after the vertices of the first i − 1 layers have been removed. Give an O(n^2 )-time algorithm to find all convex layers of a given set of n points.

A set of points with four convex layers.

  1. Prove that finding the second smallest of n elements takes n + ⌈lg n⌉ − 2 comparisons in the worst case. Prove for both upper and lower bounds. Hint: find the (first) smallest using an elimination tournament.
  1. Basic polygon computations (assume exact arithmetic)

(a) Intersection: Extend the basic algorithm to determine if two line segments intersect by taking care of all degenerate cases. (b) Simplicity: Give an O(n log n) algorithm to determine whether an n-vertex polygon is simple. (c) Area: Give an algorithm to compute the area of a simple n-polygon (not necessarily convex) in O(n) time. (d) Inside: Give an algorithm to determine whether a point is within a simple n-polygon (not necessarily convex) in O(n) time.

  1. We are given the set of points one point at a time. After receiving each point, we must compute the convex hull of all those points so far. Give an algorithm to solve this problem in O(n^2 ) total time. (We could obviously use Graham’s scan n times for an O(n^2 log n)-time algorithm). Hint: How do you maintain the convex hull?
  2. ⋆(a) Given an n-polygon and a point outside the polygon, give an algorithm to find a tangent.

(b) Suppose you have found both tangents. Give an algorithm to remove the points from the polygon that are within the angle formed by the tangents (as segments!) and the opposite side of the polygon. (c) Use the above to give an algorithm to compute the convex hull on-line in O(n log n)

  1. (a) A pair of polygon vertices defines an external diagonal if the line segment between them is completely outside the polygon. Show that every nonconvex polygon has at least one external diagonal. (b) Three consective polygon vertices p, q, r form a mouth if p and r define an external diag- onal. Show that every nonconvex polygon has at least one mouth.

Two external diagonals Two mouths

  1. A group of n ghostbusters is battling n ghosts. Each ghostbuster can shoot a single energy beam at a ghost, eradicating it. A stream goes in a straight line and terminates when it hits the ghost. The ghostbusters all fire at the same time and no two energy beams may cross. The positions of the ghosts and ghostbusters are fixed points in the plane.

(a) Prove that for any configuration of ghosts and ghostbusters, there is such a non-crossing matching. (Assume that no three points are collinear.)

(b) Show that there is a line passing through one ghostbuster and one ghost such that the number of ghostbusters on one side of the line equals the number of ghosts on the same side. Give an efficient algorithm to find such a line. (c) Give an efficient divide and conquer algorithm to pair ghostbusters and ghosts so that no two streams cross.