Determine the closest pair - Programming

Question posted in Computer Software on 05 2010
Rate question difficulty level 2 Votes
Given an array of points, determine the closest pair.
 
 
38 Answers
 
Usually the interviewer is looking for the simple answer to this question, and this would be sufficient:
public static PointPair slowClosestPair(XYPoint[] points) {
public static XYPoint point1;
public static XYPoint point2;
public static double dmin = 999999999;

for (int i=0; i < points.length - 1; i++) {
for (int j = i+1; j < points.length; j++) {
double x1 = points[i].x;
double y1 = points[i].y;
double x2 = points[j].x;
double y2 = points[j].y;
double distance = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
if (distance < dmin) {
dmin = distance;
point1 = points[i];
point2 = points[j];
}
}
}
PointPair closest = new PointPair(point1, point2, dmin);
return closest;
}

However for large numbers of points, this is inefficient.
The wiki article on this topic is quite sufficient:
http://en.wikipedia.org/wiki/Closest_pair_of_points_problem

05/22/2010
 
 
Eko

Heya i am for the pimrary time here. I came across this board and I find It truly useful & it helped me out much. I hope to present something back and help others such as you helped me.

02/20/2012
 
 
Roq3AU , [url=http://jyegjoqtouoo.com/]jyegjoqtouoo[/url], [link=http://hjbonjsgnpty.com/]hjbonjsgnpty[/link], http://xsgifjhwicyo.com/

02/23/2012
 
 

02/28/2012
 
 
Once upon a time, I turned pages for Jamie when he performed the Kreutzer Sonata at a studio class. This was before I played it myself, so I was unfamiliar with the theme & variations movement. There's one particular variation which is 2 straight pages of 16th notes, and 2 repeats. I made the mistake of glancing away from the page for a second, and discovered to my horror when I looked back that I couldn't remember a) where we were, and b) whether we had done the repeats. I ended up half-standing & hovering for what seemed like an eternity, with Jamie kindly giving me subtle no shakes and finally a clear yes nod.Then there was the time that I turned for a friend playing in a vocal recital @ Scotiafest. He asked me at the last minute as a favour, so I accepted, forgetting that I was battling the remnants of a nasty cough. There's nothing like being on stage and NOT BEING ALLOWED TO COUGH that will make you want to cough up a lung. I managed to get through the entire thing without once coughing during a piece, but then had a friend in the audience comment on the odd expression on my face at various times.

cheap auto insurance quotes compare cialis levitra viagra

03/07/2012
 
 
Once I received a call offering me a decent sum to turn for a pianist for a chamber music concert. I was pleased to finally get paid for something I'd been doing pro bono for years. I got there early and met with the pianist. He seemed high-strung but some people are before a concert. I clarified repeat issues with him and he assured me he was a clear nodder.The concert began and I soon saw why he was so high-strung; his mediocre technique and limited musicality made him a bad choice to play the well-known Beethoven and Brahms trios he was tackling (almost literally, football player style). We got towards the end of the first page and he did not nod. I figured, Maybe he likes memorize the beginning of the next page and have late turns. Nope as we reached the last two beats he abruptly turned his heard toward me and, in a low, gruff voice barked, Turn! This disagreeable ritual was repeated for most of the performance. I thought it might have been less disruptive for him and the audience to nod as he said. No such luck. I made it through and didn't mess it up, but he really unnerved me and I dare say I was very deserving of my pay that evening.

ultram cialis tablet

03/07/2012
 
 
Hi Rosemary,Thank you for updating me on missing classmate Richard Wells. You were right that he was not inthe class of 1962. I had recently emailed his brother Dan, and he informed me that Richard hasbeen teaching and living in China the last six years.Regard, Charlene (Demonet) Fisher


online auto insurance car insurance qoutes

03/08/2012
 
 
I am exploring this subject as part of a report I need to do on possible careers I might choose. Thank you for your post it has valuable information on this topic.
Portland property management

03/08/2012
 
 
Wow! I really appreciate the thought that you put into this article. This topic has been something I have been looking into for a few hours and your post is one of the best I have read.
public speaking training

03/10/2012
 
 
I have been teaching a class and we are looking at this subject in the next week. I will be directing my student to look at your post for good information.
best antivirus

03/10/2012
 
 
I have been interested in this topic for quite some time. I have been researching it for a couple of hours and found your post to be very interesting. Cheers.
Cheap Herbal Incense

03/11/2012
 
 
I am currently looking into a career change and this post helped to see another aspect of the industry. I appreciate your article.
love poems for him

03/13/2012
 
 
dpm

he informed me that Richard hasbeen teaching and living in China the last six years.Regard, Charlene (Demonet) hc commercial furniture

03/25/2012
 
 
There is so much that goes into this when you are programming. You really have to do your homework on this. It will pay off in the long run. Hockey Jersey

03/27/2012
 
 
a friend in the audience comment on the odd expression on my face at various times. Cheap Web Design

04/03/2012
 
 
it helped me out much. I hope to present something back and help others such as you helped me.essay services

04/03/2012
 
 
I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information?

Regards,
Essay Writing Help

04/10/2012
 
 
Part of a class I am taking involves this particular subject and I am researching for information to use in an upcoming report. Your post is really helpful; do you have any others on this topic?
good jokes

04/10/2012
 
 
The wiki article on this topic is quite sufficient: accounting firm los angeles

04/13/2012
 
 
I hope to present something back and help others such as you helped me. horoscope du jour gratuit

04/14/2012
 
 
Thank you for your post it has valuable information on this topic. 格安 航空券 海外

04/14/2012
 
 

04/17/2012
 
 
Kind of amusing post. information that given are relevent. It also give us some resource to think far more. A truly likely post. The explanations are perfect. Seems the topic is well-known to the writer. i have really learnt those things which were behind the curtain! seo writers

04/17/2012
 
 
it for a couple of hours and found your post to be very interesting. radiology technician salary

04/20/2012
 
 
Best approach would be this one "The Federal Reserve should have responded by building up our reserves of their currencies at the same time, but did not.

Regards,
Cheap Tools

04/23/2012
 
 
We dont wanna go there "I really like accesories on the glass of alcohol drink. They look very cute and artistic."

Regards,
Repair Parts

04/23/2012
 
 
I ll be back again in the future to check out other posts that you have on your blog. detoxify2cleanse

04/23/2012
 
 
not what he likes, as it their wedding, not his. He loves chanting the adequate Seven Alliance Blessings for the discount party dresses and the benedict in Hebrew, interspersed with seven English blessings of the couple’s choice, that allege to who they are as a couple. The English blessings may be recited by him, his co-officiant, if he has one, or by a ancestors acquaintance or friends. One of the warmest wedding shawls in about every commemoration he officiates is the Priestly Blessing

04/24/2012
 
 
I was pleased to finally get paid for something I'd been doing pro bono for years. онлайн казино

04/29/2012
 
 
Once upon a time, I turned pages for Jamie when he performed the Kreutzer Sonata at a studio class. seo company los angeles



04/29/2012
 
 
This disagreeable ritual was repeated for most of the performance. clubs in hollywood



04/30/2012
 
 
Thank you for your post it has valuable information on this topic. you make my dreams come true lyrics

05/02/2012
 
 
I managed to get through the entire thing without once coughing during a piece, but then had a friend in the audience comment on the odd expression on my face at various times. multiple choice questions service

05/04/2012
 
 
I was pleased to finally get paid for something I'd been doing pro bono for years. los angeles criminal defense attorney



05/07/2012
 
 
These cultural relativist arguments do not always hold however, as many local champions in these regions strive to implement both SSR and streamline human rights through that process. Seo Services

05/08/2012
 
 
I got to know it from my elder sister who owns enviable luxury Coach bags. Coach Outlet Online Store is established to be your home shopping paradise.
anvelope

05/09/2012
 
 
I'd been doing pro bono for years cafe furniture

05/12/2012
 
 
ese regions strive to implement both SSR and streamline humoptimizare seo

05/15/2012
 
 
Add an answer*
 
Your name
Email
 
Company: Microsoft
Location: United States
developers programming

add a question

arrow_blue


Now hiring!
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------