Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is in java. It has to use merge sort to sort the slopes of all the points. Write a program that reads N points,

This is in java. It has to use merge sort to sort the slopes of all the points.

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 (Merge Sort).

Your program should read input from a text file called points.txt that is in the same directory as your java source and class files. The file should contain the coordinates of a set of points in the format shown below:

(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)

You must use the name points.txt for your input file and you can hardcode the filename in your Java program. For testing we will use different sets of points in a file with the same name - points.txt.

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. In the above example, there is a set of four points that lie on the line y = x, and, another set of five other points, that line on the line y = x+1. There is another set of four collinear points too you could find that out.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions