0

I am getting (x,y) coordinates value from MySQL table. Suppose there are 50 such points.

I want to apply nearest neighborhood algo on these points to get most central/dense points among all.

  1. For each points find nearest neightbour using euclidian distance formula sqrt[(x2-x1)^2 - (y2 - y1)^2]
  2. Point which appears maximum times as nearest neighbour should be marked as dense/center point

I have two alternatives.

  1. Sending coordinate values to c++ compiled executable server process which performs above task and return resulting value
  2. perform above processing in php script itself to get the result

Can some one tell me which one is faster and appropriate?

Kulbir Saini
  • 3,926
  • 1
  • 26
  • 34
user3245689
  • 149
  • 1
  • 1
  • 11
  • 1
    Go with the PHP algorithm first, as the development cycle is quicker. If you find that speed is an issue, then first identify where the bottleneck is, then go about fixing it. You may find it's at the database, at which point it doesn't really matter which language is talking to it. – Jonathon Reinhart Feb 18 '14 at 07:26
  • 1
    Note: The manhattan_distance abs(x2-x1) + abs(y2 - y1) is good enough here. –  Feb 18 '14 at 07:55
  • @DieterLücking: any reference? is there any other such formula for this short of case? – user3245689 Feb 18 '14 at 09:00

1 Answers1

1

It is well known that PHP is slower than C++. But for small number of computations it really does not matter. In your case the algorithm has complexity O(n^2). For about 50 points ( as mentioned in the question ) it is not recommend to use C++ for this purpose as the overhead created by making the system is more compared to benefits you get.

If you have huge calculations to be done you may go for C++.

Have a look at this, it may help you.

Community
  • 1
  • 1
Chethan N
  • 1,110
  • 1
  • 9
  • 23