We are going to implement the following sort algorithms for our tests:
We will also create a function to fill up our collection with random data in order to test the sort algorithms with a sufficiently large data set. The sort algorithms listed above are the ones that every computer science student learns in college and are the primary sort algorithms found in real-world applications. Before we actually write code to implement them, let’s discuss a few basic facts. These algorithms can be grouped into two categories based on their algorithmic complexity:
As you may have guessed, n log n complexity implies an inherently faster algorithm than one of quadratic complexity; the tradeoff is in the code itself. Faster algorithms in the case of sorting involve recursion, multiple arrays, and complicated data structures, but they run circles around their slower cousins. Choosing the proper sort algorithm is a subject unto itself, but in this article we will cover the general factors to be considered when choosing a sort algorithm. First though, we need to whip up a touch of code to create a big data set. In the example below, set $numItems to however many data values you want in the collection. function makeWord() $return = ''; return $return;
blog comments powered by Disqus |