Menu
Create Custom Side Menus
Frodo's Ghost | PHP Sort Algorithms
50682
post-template-default,single,single-post,postid-50682,single-format-standard,eltd-core-1.0.1,ajax_fade,page_not_loaded,,borderland - frodosghost-child-ver-1.0.0,borderland-ver-1.2, vertical_menu_with_scroll,smooth_scroll,side_menu_slide_with_content,width_470,paspartu_enabled,paspartu_on_bottom_fixed,wpb-js-composer js-comp-ver-4.4.4,vc_responsive

PHP Sort Algorithms

A play to implement some sorting algorithms PHP.

Not built for speed. Built to understand functionality. You would better off using internal sorting algorithms for speed.

Quick Sort

Quick sort is usually an effective sorting algorithm. This implementation is about 80% slower than the default sort() function within PHP.

Wikipedia also mentions that this is a “naive implementation“. Taking the first element in the array can be a low number (if we’d already sorted some of the array), and therefore bring us close to O(n2)… which is bad.

 

Photo by Aleks Dahlberg on Unsplash

james
No Comments

Sorry, the comment form is closed at this time.