Search This Blog

Monday, July 12, 2010

Sorting an Array of Arrays in PHP --> Need a Good Algorithm

Programmer Question

I have an array of 15000 elements each of which is an array of 4 elements. I want to sort by the second element of the 4. Originally I made the original array's keys the second element and then k-sorted but unfortunately, some of the second elements are duplicates and since one key can't refer to multiple elements i lost some elements in transition. I could bubble sort by the second element but I'm looking for something that runs at least on the order of nlog(n). Can anyone think of a good algorithm (or possibly a function in php that I don't know about) that can sort by the second element? Thank you!



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails