title: Algorithm to find 100 closest stars to the origin
body: <p>First let me phrase the proper question:</p>
  
  <p><strong>Q: There is a file containing more than a million points (x,y) each of which represents a star. There is a planet earth at (a,b). Now, the task is to build an algorithm that would return the 100 closest stars to earth. What would be the time and space complexities of your algorithm.</strong></p>
  
  <p>This question has been asked many times in various interviews. I tried looking up the answers but could not find a satisfactory one. </p>
  
  <p>One way to do it which I thought might be using a max heap of size 100. Calculate distances for each star and check if the distance is lesser than the root of the max heap. If yes, replace it with the root and call heapify.</p>
  
  <p>Any other better/faster answers?</p>
  
  <p>P.S: This is not a homework question.</p>