Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the 14 sorting algorithms and PHP arrays

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What are the 14 sorting algorithms and PHP arrays? I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

In this article, I will introduce you to the testing of the sorting algorithm written in PHP.

Here are 14 sorting algorithms:

Quick sort

Counting and sorting

Comb sort

Heap sort

Merge and sort

Hill ranking

Select sort

Insert sort

Goblin sequencing

Joint bubbling sort

Cocktail ranking

Bubbling sort

Parity sort

Bubble sorting using flags

The algorithm is not sorted alphabetically, but according to the decreasing overall speed at which they sort 8,000 elements.

Here is the size of the array used:

one

one hundred

two hundred

four hundred

six hundred

eight hundred

one thousand

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 filled with values between (1) N, where the size of the N exponent group.

In the second case, the array is randomly populated with values between (1), where PHP_INT_MAX is the maximum value of type INT in the current system, which in my system is 2 ^ 63 or about 9.2233720368548E+18.

Each test was carried out three times, and then the arithmetic average was taken.

An array of 1000 elements

Sort all algorithms in the current array size.

An array of 30000 elements

At this point, the five fastest algorithms are tested: count sort, quick sort, comb sort, heap sort and merge sort.

An array of 200000 elements

At this point, the five fastest algorithms are tested: count sort, quick sort, comb sort, heap sort and merge sort.

An array of 2000000 elements

In the final round of 2000000-element testing, only two algorithms were tested: count sort and quick sort.

Summary

Quick sorting is a well-deserved good algorithm. Count sorting works well in the range of small values; in other cases, it can't be handled because of low memory. Cocktail ordering is a bad choice for random values. Bubbling sorting and its deformation are not suitable for practical application.

Source code of all algorithms + result: 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 ().

After reading the above, have you mastered the 14 sorting algorithms and the methods of the PHP array? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report