Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a follow up to my original question: I need help on this one. I have a hard time to figure out the condition

This is a follow up to my original question:

I need help on this one. I have a hard time to figure out the condition when 2 lines will be crossed along the way when the points are sorted using mergesort. In particular, how will an inversion happen affect the the # of intersection points with reference to 2 list of integers? I assume we will borrow the concept of mergesort and counting inversion for a list of integers to solve this problem. I will be solving this using Java. Problem: Suppose you are given two sets of n points, one set {p1, p2, . . . , pn} on the line y = 0 and the other set {q1, q2, . . . , qn} on the line y = 1. Create a set of n line segments by connecting each point pi to the corresponding point qi. Your goal is to develop an algorithm to determine how many pairs of these line segments intersect. Your algorithm should take the 2n points as input, and return the number of intersections. Using divide-and-conquer, you should be able to develop an algorithm that runs in O(n log n) time. Hint: What does this problem have in common with the problem of counting inversions in a list?

Chegg provided an answer and explain how we can count the intersections but it only showed a link on the sample java. I read the link but it's using vector algorithm, which is too complicated for me. Is there an easier way to detect the intersection using the points as integer? And, how do I put the merge algorithm to detect the intersection crossing the boundary as we use divide and conquer to divide the set into 2? Can you provide a full working code in Java for the whole thing? Thanks!

public boolean intersects(LineSegment other) {

// Check if this line segment intersects with another line segment.

// Return true if they intersect, false otherwise.

// See https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect

}

}

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

More Books

Students also viewed these Databases questions

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago