0% found this document useful (0 votes)
107 views4 pages

CSCI 8080 Design and Analysis of Algorithms: Greedy Algorithm

The document outlines 3 programming assignments for a algorithms course, including developing a graphical user interface to connect points using greedy and brute force algorithms, implementing a 2D convex hull algorithm using divide and conquer, and designing an approximation algorithm to find the minimum enclosing circle of a 2D point set.

Uploaded by

ashwathyashokan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views4 pages

CSCI 8080 Design and Analysis of Algorithms: Greedy Algorithm

The document outlines 3 programming assignments for a algorithms course, including developing a graphical user interface to connect points using greedy and brute force algorithms, implementing a 2D convex hull algorithm using divide and conquer, and designing an approximation algorithm to find the minimum enclosing circle of a 2D point set.

Uploaded by

ashwathyashokan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

CSCI 8080 Design and Analysis of Algorithms

Programming Assignment #1

Greedy Algorithm

1. Develop a graphic user interface that allows a user to set up and display a 2D point set on
screen by (1) moving and clicking the mouse, and (2) using a random number generator.
2. Make all the points connected (i.e., a path between any two points) by implementing the
two algorithms listed below.
3. Display the connected point set (i.e., the points and connecting lines) on screen.
4. Test your program with 10, 100, 1000 points respectively.
5. Analyze the computational complexity, O(.), Ω(.), and Θ(.) of the algorithms.

1. A greedy algorithm
Give (and display) a 2D point set P
1. Initialize a point s = 0
2. s = a randomly selected point p0∈P; P ← P – {p0}
3. While P is not empty
Find a pi such that it has the minimum distance(pi, s) among all pi∈P
Draw line pi-s
s = pi; P ← P – {pi}
Endwhile

2. A brute force algorithm


Give (and display) a 2D point set P
1. Initialize a point set S = ∅
2. S ← a randomly selected point p0∈P; P ← P – {p0}
3. While P is not empty
Find a pi such that it has the minimum distance(pi, sj) among all pi∈P and sj∈S
Draw line pi-sj
S ← S ∪ {pi}; P ← P – {pi}
Endwhile
CSCI 8080 Design and Analysis of Algorithms
Programming Assignment #2

Divide and Conquer algorithm

Two Dimensional Convex Hull


1. Implement a two Dimensional Convex Hull algorithm (see lecture note part 2, pages 6-9
for a description of 2D convex hull).
2. Display the point set and the convex hull on screen.
3. Test your program with 10, 100, 1000 points respectively.
4. Discuss how you would extend the algorithm to a n-dimensional Convex Hull problem.

The following algorithm is provided as a reference.

Function 2D-ConvexHull(P) // main function of the algorithm


Pre-condition: P = {pi; i = 1, 2, …, N}; a set of N 2-dimensional points.
Post-condition: L = {li; i = 1, 2, …, ||L||}; a set of line segments each defined by two vertices in
the vertex set V = {vi; i = 1, 2, … M} of the convex hull, i.e., li = {vi1, vi2}.
Interface: This algorithm calls functions 2D-SS() and 2D-Tri-Explore().

Computation:
1. lpu-pv ← 2D-SS(P); // lpu-pv denotes a line formed by two pints pu and pv; i.e., lpu-pv ::= { pu,
pv} ⊆ P; function 2D-SS(P) returns a support segment(SS) in 2D
2. For every point pj in P–{pu, pv} // bisect points between half hulls
If lpu-pv(pj) > 0 P+ ← P+ ∪ {pj}; Otherwise P- ← P- ∪ {pj};
// lpu-pv(pj) = 0 if pi is on line lpu-pv
// lpu-pv(pj) < 0 if pi is right of (below) line lpu-pv
// lpu-pv(pj) > 0 if pi is left of (above) line lpu-pv
// P+ ∪ P- ∪ {pu, pv} = P
3. 2D-Tri-Explore(lpu-pv, P+); // convex hull on points set P+ below line lpu-pv; P+ ⊂ P;
2D-Tri-Explore(lpv-pu, P-); // convex hull on point set P- above line lpu-pv; P- ⊂ P;

Function 2D-Tri-Explore(lss, PSS) // Recursive function of the algorithm


Pre-condition: lss ::= {pu, pv}; a line segment defined on point set {pu, pv}.
Pss = {pi; i = 1, 2, …, K}; a set of K 2-dimensional points all lie on one side of lss,
{pu, pv} ∩ Pss = ∅.
Post-condition: lss or recursive calls to 2D-Tri-Explore() itself.

Computation:
0. If |Pss| =0 return lss; // |Pss| is the number of points in Pss.
1. pk ← pi : pi ∈ Pss ∩ max
i
lss(pi); // pk ∈ Pss and has maximum distance to lss.
2. For every point pj in set (Pss–{pk}) // bisect and prune points
If lpu-pk(pj) > 0 P+ ← P+ ∪ {pj}; If lpk-pv(pj) > 0 P- ← P- ∪ {pj};
// P+ ∪ P- ∪ {pk} ⊆ Pss; Points in Pss-P+-P--{pk} are pruned.
3. 2D-Tri-Explore(lpu-pk, P+);
// convex hull on points set P+ in the half-space below line lpu-pk;
2D-Tri-Explore(lpk-pv, P-);
// convex hull on point set P- in the half-space above line lpk-pv;
Function 2D-SS(P) // Compute the level one support surface (segment) of P
Pre-condition: P = {pi; i = 1, 2, …, N}; a set of N 2-dimensional points.
Post-condition: lpu-pv ::= {pu, pv}; a line segment defined on point set {pu, pv}.

Computation:
N N
1 1
1. pc = [c1, c2] = [
N
∑ p i1 ,
i =1 N
∑p
i =1
i2 ]; // c is the centroid of all points pi ∈ P

2. pu ← pi : pi ∈ P & max
i
D(pi, pc); // pu in P and farthest to pc.

3. pv ← pi : pi ∈ P-{pu} & maxi


D(pi, pu); // pv in set P-{pu} and farthest to pu.
4. Return lpu-pv; // line segment lpu-pv has the maximum span among points in P.
(Note: If multiple points qualify as pu, then for each pu find a pv and return the (pu, pv) with
maximum distance. If there are still ties on (pu, pv) pairs, return an arbitrary one.)
CSCI 8080 Design and Analysis of Algorithms
Programming Assignment #3
Approximation Algorithm

Minimum Circle problem

1. Given a 2D point set P = {p0, p1, …, pn), design your own algorithm that draws a
minimum sized (i.e., minimum radius) circle that encloses all the points.
2. Display the point set and the circle on screen.
3. Describe your algorithm in English
4. Test your program with 10, 100, 1000 points respectively.
5. Analyze how close is the size of your circle (i.e., the result of your algorithm) to the
optimal one.
6. Analyze the computational complexity, O(.), Ω(.), and Θ(.) of your algorithm

You might also like