Test and Evaluation: 14 sorting algorithms and PHP array _ PHP Tutorial

Source: Internet
Author: User
Test and Evaluation: 14 sorting algorithms and PHP arrays. In this article, I will introduce you to the test of the sorting algorithm written in PHP. The following are 14 sorting algorithms: Fast sorting, counting sorting, sorting, heap sorting, and merge sorting. in this article, I will introduce you to the test of the sorting algorithm written in PHP.
The following are 14 sorting algorithms:

  • Quick sorting
  • Count sorting
  • Sort by comb
  • Heap sorting
  • Merge sorting
  • Hill Sorting
  • Select sort
  • Insert sort
  • Refined geographic sorting
  • Combined bubble sorting
  • Cocktail sorting
  • Bubble sorting
  • Parity sorting
  • Sort by flags in bubble mode

The algorithm does not sort by letters, but sorts by elements at a descending speed.

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 is passed into the sorting function.

  • In the first case, the array is randomly filled with values between 1 and N, where N is the size of the index group.
  • In the second case, the array is randomly filled with values between 1 and PHP_INT_MAX). PHP_INT_MAX indicates the maximum value of the INT type in the current system, 2 ^ 63 in my system or about 9.2233720425548e + 18.

Each test is performed three times and its arithmetic average value is obtained.

Array of the 1000 elements

Sort all algorithms of the current array size.

Array of the 30000 elements

In this case, the five fastest algorithms are tested: counting sorting, fast sorting, combing sorting, heap sorting, and merge sorting.

Array of the 200000 elements

In this case, the five fastest algorithms are tested: counting sorting, fast sorting, combing sorting, heap sorting, and merge sorting.

Array of the 2000000 elements

In the last round of 2000000 elements, only two algorithms are available for testing: count sorting and quick sorting.

Summary

Quick sorting is a good algorithm that is named by name. Counting sorting works well in a small value range; in other cases, it cannot be paid because of low memory. Cocktail sorting is a bad choice for random values. Bubble sorting and its deformation are not suitable for practical applications.

Source code + result: https://drive.google.com/file/d/0B63HSL7JD630VWdSSFgwdHR5RkU/edit? Usp = sharing

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

Http://blog.jobbole.com/68774/.

Bytes. The following are 14 sorting algorithms: Fast sorting counting sorting heap sorting merging sorting Hill sorting...

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.