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:](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3e0bb66567_81066f3e0ba9578f.jpg)
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
Get step-by-step solutions from verified subject matter experts
