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

Assingnment CS502 1

Uploaded by

rednes10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Assingnment CS502 1

Uploaded by

rednes10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Roll no BC210428197

Abdulrehman Butt Total Marks: 20

Due Date: 29-04-2024


Assignment No. 01
Spring 2024
CS502- Fundamentals of Algorithms

Uploading instructions

 For clarity and simplicity, you are required to upload/submit only one .doc/docx file.

Lectures:

 Lectures 1 to 10 are covered in this assignment.

Question No. 1 Marks: 20

The following is a set of 2-dimension space points. Each point has its x and y coordinate.:
P= {(2,11), (3,4), (5,9), (5,3),(6,8),(9,6),(12,4),(13,10),(14,8),(15,6)}
and the plane sweep algorithm pseudo code.
PLANE-SWEEP-MAXIMA(n, P[1..n])
 sort P in increasing order by x;

 stack s;

 for i ← 1 to n
 do

 while (s.notEmpty() & s.top().y ≤ P[i].y)

 do s.pop();

 s.push(P[i]);

 output the contents of stack.

You have to find out the final maximal set of points from given set of 2-dimension space point P = {p1, p2,p3,p4,p5,
…………… ,pn} using plane sweep algorithm and store it in a stack in sorted order by sweeping a vertical line from
left to right on x axis. The starting status of sweep line and stack is provided in the image. You have to follow it
and show the updated stack status in each step and the final image of the maximal set of points with stack
from left to right in the graph as well.

Note: In a given set of n points, P = {p1, p2, . . ., pn}, In 2-dimensional space a point is said to be maximal if it is
not dominated by any other point in P. The problem is to output all the maximal points of P.
Total

: 20

ANS: • Sorting Points: Imagine these points are scattered randomly on your paper.
We start by organizing them from left to right based on their x-coordinates. This
just helps us keep things in order.

• Starting with an Empty Pile: Now, picture a pile of papers (let's call them
"point papers") next to your points. At the beginning, this pile is empty.

• Putting Points in the Pile:

• Take the first point from your organized list. Put its paper on top of the pile.

• If the next point's y-coordinate is higher than the top paper on the pile, take off
papers from the top until you find a paper that has a lower y-coordinate or until the
pile is empty. Then put the new paper on top.

• Final Pile: After going through all the points like this, the pile will have papers
representing the highest points at each horizontal position. These papers are the
maximal points because there's no other paper above them at the same horizontal
position.

• Graphical View: Imagine you looking at this on a graph. The points on the pile
are the ones you would see if you drew a vertical line from left to right on the
graph, keeping only the highest points at each x-coordinate.

You might also like