Test evaluation: 14 sorting Algorithms and PHP Arrays _php tutorial

Source: Internet
Author: User
In this article, I will introduce you to the test of sorting algorithms written in PHP.
Here are 14 sorting algorithms:

    • Quick Sort
    • Count sort
    • Comb sort
    • Heap Sort
    • Merge sort
    • Hill sort
    • Select sort
    • Insert Sort
    • Sort by Goblin
    • Federated Bubble Sort
    • Cocktail Ordering
    • Bubble sort
    • Odd-even sort
    • Bubble Sort Using flags

Instead of sorting alphabetically, the algorithms sort by decreasing the overall speed of the 8,000-element sort.

The following is the size of the array used:

    • 1
    • 100
    • 200
    • 400
    • 600
    • 800
    • 1000
    • 5000
    • 10000
    • 15000
    • 20000
    • 25000
    • 30000

Each measurement uses an array of different sizes and then passes in the sort function.

    • In the first case, the array is randomly populated with a value between 1,n, where N is the size of the exponential group.
    • In the second case, the array is randomly populated with the value between 1,php_int_max, where Php_int_max refers to the maximum value of type INT in the current system, which is 2^63 in my system or approximately 9.2233720368548E+18.

Each test is performed 3 times and then the arithmetic mean is taken.

Array of 1000 elements

All algorithms are sorted at the current array size.

Array of 30,000 elements

At this point, 5 of the fastest algorithms are tested: counting sorting, quick sorting, comb sorting, heap sorting, and merge sorting.

Array of 200,000 elements

At this point, 5 of the fastest algorithms are tested: counting sorting, quick sorting, comb sorting, heap sorting, and merge sorting.

Array of 2 million elements

In the last 2 million-element test, only 2 of the algorithms were tested: counting sorting and quick sorting.

Summarize

Fast sequencing is a good algorithm to be well deserved. The counting sort behaves well in the range of small values, while others are not due to low memory. Cocktail ordering is a bad choice for random values. Bubble sorting and its deformation are not suitable for practical applications.

Source code + results for all algorithms: https://drive.google.com/file/d/0B63HSL7JD630VWdSSFgwdHR5RkU/edit?usp=sharing

Using the built-in sort function is an interesting exercise. Using interpreted PHP to write sort functions is never faster than the C variant used by sort ().

Link: http://blog.jobbole.com/68774/

http://www.bkjia.com/PHPjc/778654.html www.bkjia.com true http://www.bkjia.com/PHPjc/778654.html techarticle in this article, I will introduce you to the test of sorting algorithms written in PHP. Here are 14 sorting algorithms: Quick sort count sort comb sorting heap sort merge sort Hill sort ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.