POV-Ray : Newsgroups : povray.off-topic : 10 things to use a Min Heap for : Re: 10 things to use a Min Heap for Server Time
7 Sep 2024 21:16:01 EDT (-0400)
  Re: 10 things to use a Min Heap for  
From: Darren New
Date: 19 Jun 2008 17:35:44
Message: <485ad130$1@news.povray.org>
Warp wrote:
>   Yes, you obviously require a pointer to the first and last nodes,

Cool. It was obvious to me, but I thought maybe smarter folks had come 
up with something less obvious. ;-)

I had an interesting question today:

Given a large number N of points (say, millions) in a 2D cartesian 
space, how do you find the K points closest to the origin most 
efficiently?  E.g., you have a million (X,Y) pairs in an unsorted array; 
how do you find the five thousand pairs with the smallest (X*X+Y*Y) values?

You can actually do it with better time than "sort the whole list and 
pick the five thousand first elements". Not, AFAIK, better in the O() 
sense, but you can cut out a lot of unnecessary computation.

-- 
Darren New / San Diego, CA, USA (PST)
  Helpful housekeeping hints:
   Check your feather pillows for holes
    before putting them in the washing machine.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.