Question: This is in C++ Write a program that reads N points, specified by their 2D coordinates, and outputs any set of four or more collinear

This is in C++

Write a program that reads N points, specified by their 2D coordinates, and outputs any set of four or more collinear points (i.e., points on the same line). The obvious brute-force algorithm requires O(N4) time. However, there is a better algorithm that makes use of sorting and runs in O(N2 log N) time.

Your program should read input points from a text file. For example:

(2, 3) (4, 4) (-1, 2) (1, 0) (10, 10) (-1, 0) (3, 3) (-1, -1) (0, 1) (7, 5) (7, 8) (-4, 5) (9, 10)

The x and y coordinates of the points can be integers only.

Your program should calculate if there are any sets of four or more points that lie on the same line and output the sets.

Your program should determine these collinear point sets and output them in the format shown below. Note that in each set, points are sorted by their x-axis value.

Found these sets of four of more collinear points:

Set 1 (4 points): (-1, -1) (3, 3) (4, 4) (10, 10)

Set 2 (5 points): (-1, 0) (0, 1) (2, 3) (7, 8) (9, 10)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!