Let x, y, and z denote the three coordinate axes in the three dimensional space R3 . A point p ∈ R3 is specified by its coordinates along the three axes: p = (x(p), y(p), z(p)). For p, q ∈ R3 , we say

We are confident that we have the best essaywriters in the market. We have a team of experienced writers who are familiar with all types of essays, and we are always willing to help you with any questions or problems you might face. Plus, our writers are always available online so you can always get the help you need no matter where you are in the world.


Order a Similar Paper Order a Different Paper

Let x, y, and z denote the three coordinate axes in the three dimensional space R3 . A point p ∈ R3 is specified by its coordinates along the three axes: p = (x(p), y(p), z(p)). For p, q ∈ R3 , we say that p is dominated by q, if x(p) ≤ x(q), y(p) ≤ y(q) and z(p) ≤ z(q). Let S = {p0, p1, . . . , pn−1} be a set of n points in R3 . pi ∈ S is called a maximal element of S, if pi is not dominated by any other element of S. The set of all maximal elements of S is denoted by maxima(S). The maxima problem is: Given S, find maxima(S). You will write an efficient program to solve this problem, using the C++ or Java Standard Library functions. One brute-force algorithm to solve this problem is as follows: Compare each point pi ∈ S against all the other points in S to determine if pi is dominated by any of those points; if pi is not dominated by any of them, add it to the output set maxima(S). This algorithm takes Θ(n) time for each point pi , for a total of Θ(n 2 ) time. You will implement an efficient algorithm that is expected to run in Θ(n log n) time. The program must be in C++ or Java only. This handout discusses the implementation in C++, using the Standard Template Library (STL). The algorithm consists of three steps. I. Input: The point set S is in an input file. The first line contains the value of n (the number of points). Following that, there will be n lines, each line containing the x, y and z coordinates of one point. The points must be read and stored in an array P OINT S[0..(n − 1)] of POINT objects. The P OINT S[i] object corresponds to point pi , and has four fields: the x, y and z-coordinates (all double); the boolean field maximal indicating whether or not the point is maximal. II. Sorting: Sort the points (i.e., the array P OINT S) according to their z-coordinates, and reindex them such that z(p0) ≤ z(p1) ≤ . . . ≤ z(pn−1). The sorting must be done using the sort library function: sort(POINTS, POINTS+n); this requires that you implement the operator x(q). If x(pi) > x(q), add pi to maxima(S); also, we need to update the BST so that it represents maxima2[i..n]. The update of the BST is done as follows: First, consider the nodes in the BST whose y-coordinates are less than y(pi), in decreasing order of their y-coordinates; delete them one-by-one, until you come across a point p with x(p) > x(pi). Finally, insert pi into the BST. Each insertion or deletion in a BST takes time Θ(height of the tree). To achieve the Θ(n log n) runtime, the above BST must be a height-balanced binary search tree: At any istant, the height of the tree is Θ(log of number nodes in the tree). One example of such a tree is Red-Black Tree (see Chapter 13 in the text book). You will use the STL data structure map. It is implemented as a Red-Black Tree. In the class, I will explain how to use map. Variable M axNum has the number of elements in M axima(S). Print out M axNum and M axima(S). For each point in M axima(S), also print out its array index (i.e., the index of the point in P OINT S array). Your program should be modular, and contain appropriate procedures/functions. No comments or other documentation is needed. Use meaningful names for all variables. You will run your program on 10 different sets of points; your program should have a loop for this. All the point sets are in the input file infile.txt. The name of your program file must be maxima.[cpp or java] (corresponding to C++ or Java programs, respectively); the name of your output file must be outfile.txt.

Let x, y, and z denote the three coordinate axes in the three dimensional space R3 . A point p ∈ R3 is specified by its coordinates along the three axes: p = (x(p), y(p), z(p)). For p, q ∈ R3 , we say
CS 721: Advanced Algorithms and Analysis, Fall 2021 Programming Assignment: Maxima, Due: Tues, Nov 9 Let x, y, and zdenote the three coordinate axes in the three dimensional space R3 . A point p 2 R3 is speci ed by its coordinates along the three axes: p= ( x(p ); y (p ); z (p )). For p; q2R3 , we say that pis dominated byq, if x(p ) x(q ), y(p ) y(q ) and z(p ) z(q ). Let S= fp 0; p 1; : : : ; p n 1g be a set of npoints in R3 . p i 2 S is called a maximal element of S, if p i is not dominated by any other element of S. The set of all maximal elements of Sis denoted by maxima(S ). The maxima problem is: GivenS, nd maxima (S ). You will write an e cient program to solve this problem, using the C++ or Java Standard Library functions. One brute-force algorithm to solve this problem is as follows: Compare each point p i 2 S against all the other points in Sto determine if p i is dominated by any of those points; if p i is not dominated by any of them, add it to the output set maxima(S ). This algorithm takes ( n) time for each point p i, for a total of ( n2 ) time. You will implement an e cient algorithm that is expected to run in ( nlog n) time. The program must be in C++ or Java only. This handout discusses the implementation in C++, using the Standard Template Library (STL). The algorithm consists of three steps. I. Input: The point set Sis in an input le. The rst line contains the value of n(the number of points). Following that, there will be nlines, each line containing the x, y and zcoordinates of one point. The points must be read and stored in an array P OI N T S[0::(n 1)] of POINT ob jects. The P OI N T S [i ] ob ject corresponds to point p i, and has four elds: the x, y and z-coordinates (all double ); the boolean eld maximalindicating whether or not the point is maximal. II. Sorting: Sort the points (i.e., the array P OI N T S) according to their z-coordinates, and reindex them such that z(p 0) z(p 1) : : : z(p n 1). The sorting must be done using the sortlibrary function: sort(POINTS, POINTS+n) ; this requires that you implement the operator<. p < q if:z(p ) < z (q ), or z(p ) = z(q ) and y(p ) < y (q ), or z(p ) = z(q ) and y(p ) = y(q ) and x(p ) < x (q ). III. Finding the Maxima: Process the points, one-by-one, in decreasing order of z-coordinates. Suppose that, at some instant, you have processed the points p n 1; p n 2; : : : ; p i+1 . You must maintain the 2-dimensional maxima of these points in the ( x; y)-plane; this will be called maxima 2[( i+ 1) ::(n 1)]. It forms a staircase in the ( x; y)-plane. CONSIDER maintainingmaxima 2[( i+ 1) ::(n 1)] in a Binary Search Tree (BST) keyed on the y-coordinate; each node of BST corresponds to a point in maxima 2[ i + 1 ::n]. As we traverse these nodes in decreasing order of y-coordinate, their x-coordinates increase (thus forming a staircase). Now we want to process p i. p i has a smaller z-coordinate than the points processed so far (namely, p n 1; p n 2; : : : ; p i+1 ). So, p i 2 maxima (S ) i it is not dominated in the ( x; y)-plane by any of the points in maxima 2[ i + 1 ::n]; i.e., p i is not under the staircase. The test of whether p i is dominated by any of these points (in the ( x; y)-plane) is performed as follows: Find the point qin BST such that y(q ) is just above (or equal to) y(p i); then p i 2 maxima (S ) i x(p i) > x (q ). If x(p i) > x (q ), add p i to maxima (S ); also, we need to update the BST so that it represents maxima 2[ i::n ]. The update of the BST is done as follows: First, consider the nodes in the BST whose y-coordinates are less than y(p i), in decreasing order of their y-coordinates; delete them one-by-one, until you come across a point pwith x(p ) > x (p i). Finally, insert p i into the BST. Each insertion or deletion in a BST takes time (height of the tree). To achieve the ( nlog n) runtime, the above BST must be a height-balanced binary search tree: At any istant, the height of the tree is (log of number nodes in the tree). One example of such a tree is Red-Black Tree (see Chapter 13 in the text book). You will use the STL data structure map. It is implemented as a Red-Black Tree. In the class, I will explain how to use map. Variable M axN um has the number of elements in M axima(S ). Print out M axN umand M axima (S ). For each point in M axima(S ), also print out its array index (i.e., the index of the point in P OI N T Sarray). Your program should be modular, and contain appropriate procedures/functions. No com- ments or other documentation is needed. Use meaningful names for all variables. You will run your program on 10 di erent sets of points; your program should have a loop for this. All the point sets are in the input le infile.txt. The name of your program le must be maxima.[cpp or java] (corresponding to C++ or Java programs, respectively); the name of your output le must be out le.txt. ANY ONE INVOLVED IN CHEATING/COPYING (INCLUDING THE ONE WHOSE WORK WAS COPIED) WILL BE SEVERELY PUNISHED.

Writerbay.net

Do you have a lot of essay writing to do? Do you feel like you’re struggling to find the right way to go about it? If so, then you might want to consider getting help from a professional essay writer. Click one of the buttons below.

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now


Order a Similar Paper Order a Different Paper