Types of ordering and their performance, which one to choose?

Asked

Viewed 127 times

3

I know of various forms of ordination such as Selection Sort, Bubble Sort and Quicksort, we also have PHP functions like sort() and array_multisort().

Currently the system I developed works with Bubble Sort because it is the simplest, but from what I saw it is more time consuming, and now working on updating the system implemented the use of array_multisort(), but it came to me the doubt of how this function works and if it would not be better I create a Quicksort, currently my system works with little data so is indifferent the method chosen but thinking about the future and its maintenance which would be the best choice?

What am I ordering? It’s a array that has the distances of a point X to N points and now using the array_multisort() after ordering by distance I order by time.

  • But the intention is to know which point is closest to X ? This is information that changes or is "fixed" ?

  • @Isac the problem of the question is not the ordering that I am quietly doing my doubt is as to what would be the best way to do for improved maintenance and performance

  • I ask the question why to know the N closest points of X or points to Y radius of distance of X does not imply ordering, and will be more efficient without ordering.

  • @Isac I work with the information already calculated by the Google API, which returns me a json with the data and then I create some arrays 2 of them one being distance and the other time, and so I order them from smaller to larger

1 answer

3


First let’s use the correct terminology. You want to sort and not sort, it’s already in an order, it’s not classified.

To PHP documentation makes a comparison of what is ready to use.

Depending on what you need array_multisort() is a bad idea. But we don’t know what it needs. Even the amount of work can determine whether it’s useful or not. For example, the . NET adapts according to the data of the collection.

I can assure you that some of them should use a much more optimized Quicksort than you can do. In fact documentation says that most functions use this algorithm.

Maybe make a benchmark with each be the way forward. But do it with various sizes and various distributions of the data. Dispose in advance of those who don’t answer the semantics you need. If none suits you, start thinking about making your own, but don’t do it in PHP that has a lot overhead.

It may be that the solution is quite different from what you’re thinking and it’s not even the case to classify anything, but I’m just speculating.

I answered about some known algorithms.

Complement: Why use a pointer in this algorithm?

  • I was reading the links you put in the answer helped a lot, I will try to do the benchmark , I found the method of . NET , the ultimate goal of my system is to inform the users closest to who searches using a Google API (Matrix) so I need to rank those who are closer and less time , but thanks for the answer I will delve into the options I am finding until I decide which one will suit me best

Browser other questions tagged

You are not signed in. Login or sign up in order to post.