Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do the solution in Java. Test case: {1,10,8,6,6,2,5,1} should return 4 intersections. 1 Suppose we are given two sets of n points, one set
Please do the solution in Java.
Test case: {1,10,8,6,6,2,5,1} should return 4 intersections.
1 Suppose we are given two sets of n points, one set {P1, P2, . . . , Pr} on the line y = 0) and the other set {91, 92, ..., In} on the line y = 1. Consider the n line segments connecting each point pi to the corresponding point qi. Describe and analyze a divide-and-conquer algorithm to determine how many pairs of these line segments intersect, in O(n log n) time. See the example below. 4,944 47 93 P4 P3 PS P, P, PP2 Seven segments with endpoints on parallel lines, with 11 intersecting pairs. Your input consists of two arrays P[1.. n) and Q[1.. n) of e-coordinates; you may assume that all 2n of these numbers are distinct. No proof of correct ness is necessary, but you should justify the running time. Solution: We begin by sorting the array P[1.. n] and permuting the array Q[1.. n] to maintain correspon- dence between endpoints, in O(n log n) time. Then for any indices iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started