Question: [ Java - PriorityQueue ] analyze time complexity of this code. Many thanks! Background: Given an array containing N points find the K closest points

[Java - PriorityQueue] analyze time complexity of this code. Many thanks!

Background:

Given an array containing N points find the K closest points to the origin (0, 0) in the 2D plane. You can assume K is much smaller than N and N is very large.

E.g: given array: (1,0) (3, 0),(2, 0), K = 2

Result = (1,0), (2, 0)

(result should be ascending order by distance)

Code is:

[Java - PriorityQueue] analyze time complexity of this code. Many thanks! Background:

Question:

1: What is time complexity for line 35, line 39, independently and separately?

2. What is time complexity for line 35 - 39 (As a whole) ?

3. What is time complexity for line 44 - 46 (As a whole) ?

4. What is overall time complexity for entire method getKNearestPoints(), in best, worst and average case? What if n >> k ? and what if we don't have n >> k ?

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!