Register
Sign In
Skip over navigation
Home
Add New Question
Jobs
Products
Determine the closest pair - Programming
Question posted
in
Computer Software
on
05 2010
Rate question difficulty level
4
2 Votes
Given an array of points, determine the closest pair.
Add an answer
Share
|
38 Answers
David Hollowell
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
natjcbrhgc
Roq3AU , [url=http://jyegjoqtouoo.com/]jyegjoqtouoo[/url], [link=http://hjbonjsgnpty.com/]hjbonjsgnpty[/link], http://xsgifjhwicyo.com/
02/23/2012
fwfvzytm
HeYxgA
wrgtblbwzgpi
02/28/2012
Kathreen
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
Lettie
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
Ranessa
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
underson45
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
Comingtwiceto
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
dertsda234
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
mato12345
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
nwadatstate
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
inter4522
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
nahih
a friend in the audience comment on the odd expression on my face at various times.
Cheap Web Design
04/03/2012
vinay
it helped me out much. I hope to present something back and help others such as you helped me.
essay services
04/03/2012
star09
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
Asdrtyuio50
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
mike
The wiki article on this topic is quite sufficient:
accounting firm los angeles
04/13/2012
John
I hope to present something back and help others such as you helped me.
horoscope du jour gratuit
04/14/2012
hogg
Thank you for your post it has valuable information on this topic.
格安 航空券 海外
04/14/2012
john
Gangaur Realtech is a professionally managed organisation specializing in real estate services
Residential property in gurgaon
plots in gurgaon
And
park view grand spa
bestech grand spa
park view grand spa gurgaon
And
sector 102 gurgaon
raheja projects in dharuhera
04/17/2012
JoshuaJones
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
mike
it for a couple of hours and found your post to be very interesting.
radiology technician salary
04/20/2012
Toolman11
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
Toolman11
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
farooq
I ll be back again in the future to check out other posts that you have on your blog.
detoxify2cleanse
04/23/2012
discount party dresses
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
Adam
I was pleased to finally get paid for something I'd been doing pro bono for years.
онлайн казино
04/29/2012
Adam
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
Martin
This disagreeable ritual was repeated for most of the performance.
clubs in hollywood
04/30/2012
Martin
Thank you for your post it has valuable information on this topic.
you make my dreams come true lyrics
05/02/2012
Adam
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
Adam
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
Martin
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
Adam
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
Adam
I'd been doing pro bono for years
cafe furniture
05/12/2012
optimizare seo
ese regions strive to implement both SSR and streamline hum
optimizare seo
05/15/2012
Add an answer*
Your name
Email
Enter the code shown above:
please wait..
Company:
Microsoft
Location:
United States
Tags:
developers
,
programming
Occupations:
Software\System Architecture
,
Software\Web Development
add a question
Now hiring!
Software Development Engineer, Principal IT Job
Microsoft
Issaquah, WA
a highly motivated and experienced SharePoint Software Development Engineer who is passionate about developing and ... as a coding practitioner in software engineering required Experience with Agile Development is a plus...
---------------------------
Software Development Engineer II-BING
Microsoft Bing
San Francisco, CA
o At least two years of experience in industrial software development o Strong C++ coding and object oriented design ... Segments: Computer Science, Developer, Engineer, Engineering, Research, Software Engineer, Technology, User...
---------------------------
Senior IT Software Development Engineer Job
Microsoft
Issaquah, WA
IT We are looking for talented and highly motivated Sr. Software Development Engineer (Sr. SDE) to drive design, ... Marketing services team is part of Microsoft Marketing IT organization that manages the Microsoft.com that reaches...
---------------------------
Software Development Engineer II, MSN
Microsoft Bing
Bellevue, WA
and end user needs Advocate for and experience with agile development Quality driven. Test, test, test. Unit, TDD. ... Developer, Editor, Engineer, Engineering, Java, Publishing, Software Engineer, Technology, Test Engineer, Testing, Web...
---------------------------
Senior IT Software Development Engineer (SDE) Job
Microsoft
Redmond, WA
IT Do you want to drive changes that can affect the development and testing communities across Microsoft? The ... in software development through all phases 4-6 years development experience with C#, C++, Asp.Net and Windows...
---------------------------
Principal IT Software Development Engineer-Azure Job
Microsoft
Quincy, WA
IT Location: Quincy, WA, US Job ID: 787628-80076 Division: IT Are you passionate about building industry-leading, ... based experience with implementation, architecture and development highly preferred Proven track record of shipping...
---------------------------
Software Development Engineer in Test II
Microsoft Bing
Mountain View, CA
The Microsoft Ads Research & Development team is one of the most strategic and growing teams at Microsoft ... As part of a software company with powerful innovations and part media company with global properties, at Microsoft Ads...
---------------------------
IT Software Development Engineer (SDE) 2 Job
Microsoft
Redmond, WA
it easy. We make it work. Were looking for an experienced IT Software Design Engineer to play a key role in ... Required Qualifications: Minimum 5 years of software development experience for enterprise line of business...
Jobs
by
Simply
Hired
View all jobs