Article View: comp.lang.c++.leda
Article #67Re: nearest 2 neighbors?
From: Wolfram Schlickenrieder (KSC)
Date: Tue, 05 Sep 1995 23:25
Date: Tue, 05 Sep 1995 23:25
25 lines
1339 bytes
1339 bytes
hunter@george.ee.washington.edu (William Hunter Hudson) writes: > Is there a better way to find the nearest 2 neighbors in LEDA > than using 2 calls to S.nearest_neighbor? Example: > > p = point(x,y); > // nearest: nearest point to p > // 2nd_nearest: 2nd nearest point to p > > ps_item nearest = S.nearest_neighbor(q); // O(n^2) > S.change_inf(nearest, far_away); // O(1) > ps_item 2nd_nearest = S.nearest_neighbor(q); // O(n^2) > S.change_inf(nearest, back_to_original); // O(1) If computing distances is no too expensive -- what do you think of: compute distances ; // O(n) sort them in descending order ; // O(n log n) take the first 2; // O(1) ? Wolf
Technical Details
Message-ID:
<SCHLICKE.95Sep6012550@owl.math.TU-Berlin.DE>Path:
arc1-ca.pugleaf.net!news.cs.tu-berlin.de!schlickeReferences:
<42iau2$11p@nntp5.u.washington.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.cs.tu-berlin.de!schlicke From: schlicke@math.TU-Berlin.DE (Wolfram Schlickenrieder (KSC)) Newsgroups: comp.lang.c++.leda Subject: Re: nearest 2 neighbors? Date: 05 Sep 1995 23:25:50 GMT Organization: FB3, TU-Berlin, Germany. Distribution: world Message-ID: <SCHLICKE.95Sep6012550@owl.math.TU-Berlin.DE> References: <42iau2$11p@nntp5.u.washington.edu> NNTP-Posting-Host: owl.math.tu-berlin.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit In-reply-to: hunter@george.ee.washington.edu's message of 5 Sep 1995 20:11:46 GMT