2D Closest Pair Problem

PROBLEM:
Given an arbitrarily number of data points in 2-d space, this algorithm finds a pair of data points with minimum Euclidean distance from each other.
I read in points from a data file as follows:
100 //number of points
12.5 100.2 //each line contains the x and y coordinates of one data point
0.7 1.5
I know it seems strange to be posting such a topic since it has been addressed several places before. I have found a decent psuedocode that addresses the algorithm:
closestPair of (xP, yP)
               where xP is P(1) .. P(N) sorted by x coordinate, and
                     yP is P(1) .. P(N) sorted by y coordinate (ascending order)
if N ≤ 3 then
  return closest points of xP using brute-force algorithm
else
  xL ← points of xP from 1 to ⌈N/2⌉
  xR ← points of xP from ⌈N/2⌉+1 to N
  xm ← xP(⌈N/2⌉)x
  yL ← { p ∈ yP : px ≤ xm }
  yR ← { p ∈ yP : px > xm }
  (dL, pairL) ← closestPair of (xL, yL)
  (dR, pairR) ← closestPair of (xR, yR)
  (dmin, pairMin) ← (dR, pairR)
  if dL < dR then
    (dmin, pairMin) &#8592; (dL, pairL)
  endif
  yS &#8592; { p &#8712; yP : |xm - px| < dmin }
  nS &#8592; number of points in yS
  (closest, closestPair) &#8592; (dmin, pairMin)
  for i from 1 to nS - 1
    k &#8592; i + 1
    while k &#8804; nS and yS(k)y - yS(i)y < dmin
      if |yS(k) - yS(i)| < closest then
        (closest, closestPair) &#8592; (|yS(k) - yS(i)|, {yS(k), yS(i)})
      endif
      k &#8592; k + 1
    endwhile
  endfor
  return closest, closestPair
endif I don't understand this a 100% and how I would implement this. This has a more mathematical approach and that seems to be my problem when I look online. Is there anymore resources that anyone is aware of. Thanks for any help.

    static double d;
    private static void bruteForceClosestPair (ArrayList<Pair> points) {
        ArrayList<Pair> minPoints = new ArrayList();
        if (points.size() < 2) {
            System.out.println("Only one point!");
        else {
            d = distance (points.get(0).getX(),points.get(0).getY(), points.get(1).getX(), points.get(1).getY());
            minPoints.add(points.get(0));
            minPoints.add(points.get(1));
            for (int i = 0; i < points.size()-1;i++){
                for (int j = i+1;j < points.size(); j++) {
                    System.out.println("Checking "+ points.get(i) +  " and " + points.get(j) );
                    if(distance(points.get(i).getX(), points.get(i).getY(), points.get(j).getX(), points.get(j).getY())< d){
                        d = distance(points.get(i).getX(), points.get(i).getY(), points.get(j).getX(), points.get(j).getY());
                        minPoints.clear();
                        minPoints.add(points.get(i));
                        minPoints.add(points.get(j));
        System.out.println("minimum is " + d);
        System.out.println("My pair points be " + minPoints.toString());
    }I am able to check every point using a brute force attack, but the problem that I am trying to accomplish is finding a divide and conquer/recursive approach to solving this problem. I hope this makes sense. How can I go about this?

Similar Messages

  • Macbook pro retina - Sennheiser mm450 bluetooth pairing problem

    Sorry people but have, with surprise, comunicate a bluetotth pairing problem of my Sennheiser MM450 bluetotth  headset with my new macbook pro retina 15".
    No headset detected by may mac.
    No problems with other bluetooth devices and this macbook.
    No problems with this headset and iphone or other computer.
    I'm very disapointed.
    Hope to have some suggestion for solve the problem
    Thanks

    It may be necessary to turn on the aptX codec via Bluetooth Explorer -> Utilities -> Special Options
    That did the trick for me.
    The bluetooth explorer used to be available by pressing option then the bluetooth button, but now its bundled seperatly either with xcode or here :https://developer.apple.com/downloads/index.action?name=bluetooth%20explorer

  • SL3100 Pairing problem and the lack of intelligent reply from creative

    I posted a message a day or two ago about having trouble pairing my SL300 with its own adapter. This was a brand new out of the box unit. Since the unit was new I thought I'd ask Creative to assist and wrote to their tech support, who returned with following response. In my opinion this response shows a total lack of product knowledge or any concern whatever that one of their OWN products does not work. Here is the response I received when I could not pair THEIR ADAPTER with THEIR HEADSET? both of which came in a sealed box from THEM?I apologize for any inconvenience this may have caused you. However, let me try my best to help you out in resolving this issue.
    To assist you on this, you may want to try on the following
    troubleshooting tips and see if they could help:
    1. Try unpairing the headset. A headset can only be paired to one device at a time.
    2. Recharge the headset and try pairing the headset once more. A headset will not automatically pair with the device again when powered on.
    3. Check that the device being paired to the headset has its Bluetooth feature(s) turned on.
    4. Ensure the headset is turned on and the battery is fully charged.
    5. Ensure the headset is within one meter of the device while pairing.
    6. Remove and replace the device's battery (if the device has a replaceable battery) and try pairing the device and the headset again.
    7. If prompted by the device for a passkey, enter 0000.
    8. Make sure the Bluetooth headset and the device are both running compatible protocols.
    9. Make sure the Bluetooth headset and the device are both running compatible protocols.
    10. Make sure there are no obstructions between the device and the headset when pairing.
    11. Make sure the pairing is being initiated on the headset, not the device the headset is being connected to.
    If the issue would still persist, the product may need to be repaired/replaced.
    The problem you described indicates your unit may require repair or replacement. If possible, try exchanging the product for another from the vendor, for this may be much quicker and easier than having an RMA (Return Merchandise Authorization) issued. If this is not possible, an RMA will need to be arranged to have your product tested for repair/replacement.
    If the product has exceeded its one year warranty period, an out-of-warranty RMA will need to be issued. This type of RMA requires a non-refundable US $25.00 diagnostics and handling fee for each out-of-warranty product. The fee is applied toward the complete cost of repair/replacement. If the cost of the repair/replacement exceeds the initial diagnostic fee, the RMA department will contact you to obtain your authorization for finance of the remaining fee. If the product has not exceeded its warranty, no diagnostic fee is required.

    It is pretty standard practice for you to get a more general response first time as it eliminates most users problems. And, unless you doing the pairing incorrectly, it seems the email does suggest an answer (its faulty) and recommends replacement.
    I would assume the problem is its broke too, so just try to return it to the shop you got it from.
    Message Edited by lakin on 04-15-2007 10:02 PM

  • Solved Bluetooth cell phone pairing problem after 10.4.8 update

    I am not sure why it works this way,but I tested it a few times and it was consistant.First I updated to version 10.4.8 . The 3 motorola razor phones I have were not able to pair anymore at all.Under 10.4.7 file transfers were no problem and pairing always occured.I use the d-link dbt 120 bluetooth adapter and until now (with 10.4.8) communication was never a problem when the adapter was attached to my belkin hub where it has a docking area for flash drives and mp3 players etc... .
    When I now try to use the adapter on the usb hub it doesn't work now at all.I get messages that communication is not possible etc... . When I put the adapter on the one usb port on the front of my powermac g5 then I get very quick pairing ,file transfers etc... . I moved the bluetooth adapter back and fourth between the hub and the front of the computer and the result was always the same.The port on the mac works and others don't anymore.
    The other ports on the usb hub worked fine with 10.4.7 but not with 10.4.8. It seems like the hub fell from grace or something with the new update. I felt better when I could get it to work. I wish I would have found this out before I did the archive and install though to go back to 10.4.7 .
    I reupgraded to 10.4.8 then found the solution to my problem maybe 10 minutes away from a second archive and install to take me back to 10.4.7.

    Hi Ralph,
    Thanks for your response! Unfortunately I am enough of a newbie not to understand the implication of what you said Where should I look for these devices, and are they conflicting with iChat somehow? Do you mind telling me what action to take to fix this?
    In the meantime I did a 10.4.9 update and airport stopped working completely. I talked to Apple support and they had me do a factory reset on my airport extreme basestation and reconfigure it in order to get to work again, and I have not tried video iChat since that happened.
    Thanks!
    Seleya
    Powerbook 15" Hi Res 1.67 GHz 2 Gb RAM   Mac OS X (10.4.9)  
    Powerbook 15" Hi Res 1.67 GHz 2 Gb RAM   Mac OS X (10.4.9)  

  • Pairing problems between my new nokia n82 and blue...

    I tried pairing up my n82 and bh-208 last night, but couldn't get it to work. The n82 recognised other bluetooth devices. My bluetooth was definitely working, as I had used it earlier with another mobile fone. I've followed all the instructions and paired other bluetooth headsets before, but no luck this time, even after trying several times. Any suggestions?

    i had same problem, i just kept chimping about until it finally gave in and connected. no idea what happened, possibly that you can connect TO the phone, but it won't connect TO OTHERS, but y, that is the question. come on NokNok....what's the fix?
    MS

  • Microsoft Bluetooth NoteBook Mouse 5000 pairing problem with Mac OS X

    On day one which was last week Friday, Sept 25, my BT mouse was working perfectly fine, just until this morning and last night it stopped working.
    It does detect the mouse, it establishes connection but then I get an error message " The pairing attempt was unsuccessful. Make sure your mouse is in range of this computer, turned on and "discoverable" When ready click Continue to try again"
    Any help will be appreciated, thanks..

    I had the same problem. The cure is to boot off of the OSX DVD and when it attempts to find a mouse hold down the connect button on the bottom of the mouse. Keep holding it down until OSX recognizes the mouse. It may take a minute or two. After the mouse has been recognized you can exit before the installation requires software to be transferred. Then just select a normal reboot on the exit menu option.

  • Bluetooth headset pairing problem

      I got E71-1 (11) firmware version 210.21.006 device and i also got this bluetooth headset HBH-PV720  http://www.sonyericsson.com/cws/products/accessories/overview/hbh-pv720
    And i can't pair the phone with the bluetooth headset
     Does E71 support this Headset? Or i am doing something wrong? 
    Type the name of a command and press enter to execute it, or help for assistance.

    many have talked about its need, I dont know when a software update will enable this
    Click here to Backup the data on your BlackBerry Device! It's important, and FREE!
    Click "Accept as Solution" if your problem is solved. To give thanks, click thumbs up
    Click to search the Knowledge Base at BTSC and click to Read The Fabulous Manuals
    BESAdmin's, please make a signature with your BES environment info.
    SIM Free BlackBerry Unlocking FAQ
    Follow me on Twitter @knottyrope
    Want to thank me? Buy my KnottyRope App here
    BES 12 and BES 5.0.4 with Exchange 2010 and SQL 2012 Hyper V

  • TS3048 wireless keyboard pairing problems

    hello there
    have been trying to pair a wireless keyboard to my macbook, am given a code by the BlueTooth assistant and told to enter it into the dialogue box when prompted, but do not receive the prompt and the pairing attempt times out.
    any idea what the problem might be?
    cheers

    Hello:
    Was the KB, by chance, paired with another device?
    Barry

  • TS1569 Wireless Keyboard Pairing Problems

    I have an iMac mid 2007. Everything was working fine until today. I replaced the batteries in my wireless keyboard. When I turned on my computer it wouldn't recognize the keyboard and I am having difficulty pairing it again. The green light turns on for a few seconds and goes off. The caps lock light works and everything, but it won't pair. Please help.

    Hello;
    It is not helpful to you, but resetting the SMC frequently fixes similar problems.
    If you have a wired KB, try resetting the PRAM.
    If you do not, try trashing a preference file (com.apple.bluetooth.plist) and restarting.
    I think it is unlikely, but I suppose the KB decided to fail at the same time you replaced the batteries.
    If you happen to be near an Apple store, take it in and see if it will pair with their equipment.
    Barry

  • N80 and GPS pairing problem

    I have a BT GPS module (Holux M-1000B) and when I pair it for the first time with my N80 it works ok as long as I don't disconnect it. But if I stop using it (for example if I stop in Sports Tracker) I have to remove the pairing to reconnect. I've tried everything and the only way to reconnect is to remove the pairing and pair them again and that is pretty annoying.
    Is this a known problem with other GPS modules also or is it with this one? It works perfectly with my laptop, but I haven't tried using it with other mobiles.
    (N80 fw v. 5.0719.0.2)
    Message Edited by aanirone on 29-Dec-2007 08:40 PM

    Hi aanirone
    If it is of any help I notice that Nokia Maps application is now available for the N80, which has not been supported since Smart2Go beta version was withdrawn:
    http://europe.nokia.com/A4509291
    As N80 firmware has now reached end of development, you would expect that this application has been tested with last software release in the circumstances.
    Happy to have helped forum in a small way with a Support Ratio = 37.0

  • IPad IOS 5 Bluetooth Pairing Problem

    I have iPad 1 with Brookstone Bluetooth Keyboard.  Since upgrading to IOS 5, every time I turn off the iPad it loses the pairing with the keyboard and I have to re-pair the device.  This worked fine before upgrading to IOS 5.  Does anyone have a solution to this problem?

    If you called AppleCare they would have you do a reset. Press & hold the Power and Home buttons together for 10+ seconds, ignoring the red power-off slider, until you see the Apple logo. If that did not solve the issue they would have you backup the iPad and then restore it to its factory settings. Be sure to transfer any purchases to your computer before restoring the iPad.

  • Magic Trackpad - Pairing Problems Switching Between OS X & Windows

    My system has Mac OS 10.6.4 (with Magic Trackpad update 1.0 installed) and Windows 7 (with Bootcamp 3.1 plus the "Magic Trackpad/27" Cinema Display" update). The Trackpad works correctly after setup in OS X with all functions working even after reboots. The Trackpad also works correctly after setup in Windows 7 (with passkey 0000) and continues to work correctly with the supported features with multiple reboots into Windows 7.
    The problem is that after using Windows, when I reboot to OS X the Trackpad will not function. It shows as paired but disconnected and will not stay connected. If I un-pair and then re-pair it will work. And the same thing happen when I switch from OS X to Windows - it shows as paired but unconnected and the only way to get it to work is to un-pair and then re-pair.
    I had a similar sort of problem with the Magic Mouse and found that if I un-pair in OS X, pair in Windows, and then pair in OS X it will work with both. But the Trackpad won't work this way, even after trying this. I think the problem is that the Trackpad won't allow paring with two different systems (for the obvious reason) but isn't designed to accommodate the Bootcamp scenario.
    I really like the Magic Trackpad and would like to be able to use it on those rare occasions when I need to use Windows without the hassle of reinstalling it each time I boot a different OS. Any solution to this problem?

    UPDATE: I installed Vista on Bootcamp and tried the Magic TrackPad driver. It has the same problem. I can get the device to work as advertised on the initial install and reboots in the same OS. But when you switch from Windows to Mac OS X (or vice-versa) the device will not work: in Windows is listed as paired and connected, but does not work. In Mac OS X, it will not connect automatically and does not work. If you manually try to connect the Bluetooth icon briefly shows connected and then disconnects.
    I sent a bug report to Apple as a "developer" and they state that it is a known issue. I guess we simply wait for them to get around fixing the drivers at some point in the distant future. Clearly they ignore these forums altogether. The experience has left me disappointed with Apple and their slow and inadequate response to problems. I would rather they devote some resources to getting their existing products to work instead of wasting resources to add iPhone-style displays to Mac OS X. If I wanted buggy drivers and no support I should have just stayed with Windows.

  • IPhone 4 pairing problem

    I bought a Monster Cable Clarity HD Micro speaker (bluetooth) and had no problem pairing it to my MacBook Pro or my iPad.  However, on my iPhone 4, the phone recognized the speaker, identified it on the screen but would not present a screen to input the PIN ...and pairing failed.  Repeated attempts all provided same result.  Any help is appreciated.  jw

    Thank you, for taking the time to communicate your thoughts.
    My first question is : Will the iPhone 4 work with the WEP870?
    Second if it will,  what must be done to make that happen?
    It should be in the best interest of the Apple community to assist users of apple products in getting the best possible value out of the products. That would include the use of compatible OEM devices. I have been seeking information from other sources. If that had been helpful I wouldn't be here. My hope was that some kind person would have had a similar experience and would know the answer to my questions. If there is no one out there that can answer the questions, that will not surprise me. 

  • Pairing problem with Docs to Go and Windows 7

    First, I'm not sure this is the correct forum. I've setup a new Windows 7 laptop and installed Docuemnts to Go (latest version downloaded, no updates needed). An was able to pair with both my iPhone and my iPad. iTunes syncs fine (but that's using a USB cable). I entered folders and files for Docs to Go to sync (the same ones as on my old laptop running Windows XP). Then Docs to Go desktop couldn't find the iPhone and I needed to pair again.  I have reinstalled the desktop application, double checked Bonjour, both laptop and iPhone are on the same WiFi.  But, I can't pair the two devices to sync my folders and files. Dataviz hasn't been any help - followed all their instructions, e-mailed Tech Support and got a reply that said to do exactly what I told them I did!
    Anyone have this problem? Anyone have a solution? 
    It seems to be a problem with one or the other (desktop application or iPhone app) not communicating via WiFi properly.  I'm assuming that that's a Bonjour issue.
    nlc

    Try disabling your security system's firewall (McAffee, Norton or the like).  You can also try this: http://h20180.www2.hp.com/apps/Nav?h_pagetype=s-926&h_lang=en&h_client=s-h-e17-1&h_keyword=dg-NDU&ju...
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Having issues with Motorola S10-HD not paired problems?

    Trying to pair my Motorola S10-HD headphones via bluetooth and it's not pairing. Keeps telling me it's not paired.

    Try resetting the sd10-hd .  That solved my problem. I was able to pair with my iPhone 5.
    Follow this link to instruction to reset the s10-hd, https://motorola-global-portal.custhelp.com/app/answers/prod_answer_detail/a_id/ 59350/p/1422,2690,7709
    Essentially hold down the + and 0 (power button) until the LED turns blue. Then power off the headset and power on.  Put the iPhone in discoverable mode and they should now sync.

Maybe you are looking for