Docsity

Homework 2 Questions - Data Structures - Spring 2002 | CMSC 420, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
CMSC 420: Data Structures
Spring 2002
http://www.cs.umd.edu/class/spring2002/cmsc420/
HOMEWORK 2: Due April 2, 2002
Suppose you have a text file called RectInwhere each line in the text file contains information
about a rectangle. A line in the text file has the format
RectangleID LLx LLy URx URy
This information says that there is a rectangle named RectangleId (string type) hose lower left
corner is
(
LLx
;
LLy
)
and whose upper right corner is
(
URx
;
URy
)
.
LLx
;
LLy
;
URx
;
URy
are all integers.
You are required to write an algorithm called find-intersections. What the algorithm does is to
take a file RectIn of the above kind as input and it returns as output, a file RectOut having the
same structure. The contents of the output file are determined as follows. If there are two distinct
rectangles
r
1
;r
2
in RectIn that intersect, then theoutput must contain a rectangle describingthe in-
teresction of
r
1
and
r
2
(note that the intersection of two rectangles is also a rectangle). The rectangle
obtained in this way should have the name
r
1:
r
2
.
Your output file must not contain any redundant or unnecessary information (i.e. all rectangles in
the output must be the intersection of two rectangles in the input and the intersectionmust not be
empty).
1

Partial preview of the text

Download Homework 2 Questions - Data Structures - Spring 2002 | CMSC 420 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CMSC 420: Data Structures

Spring 2002 http://www.cs.umd.edu/class/spring2002/cmsc420/ HOMEWORK 2: Due April 2, 2002

Suppose you have a text file called RectInwhere each line in the text file contains information about a rectangle. A line in the text file has the format

RectangleID LLx LLy URx URy

This information says that there is a rectangle named RectangleId (string type) hose lower left corner is (LLx; LLy) and whose upper right corner is (URx; URy). LLx; LLy; URx; URy are all integers. You are required to write an algorithm called find-intersections. What the algorithm does is to take a file RectIn of the above kind as input and it returns as output, a file RectOut having the same structure. The contents of the output file are determined as follows. If there are two distinct rectangles r 1 ; r 2 in RectIn that intersect, then the output must contain a rectangle describing the in- teresction of r 1 and r 2 (note that the intersection of two rectangles is also a rectangle). The rectangle obtained in this way should have the name r 1 : r 2. Your output file must not contain any redundant or unnecessary information (i.e. all rectangles in the output must be the intersection of two rectangles in the input and the intersection must not be empty).