A ramble on search/Sort in Python

Source: Internet
Author: User

In the data structure that piece, search ordered find/two find/hash find, while sort have bubble sort/select sort/Insert sort/merge sort/quick sort. If you encounter data volumes and arrays in different ways, you may need to use a hybrid algorithm based on time complexity considerations. If you write in C, it is a headache and a high threshold of the process, Python is a very simple way to make such algorithms available to everyone.

Sort, Python uses a sort function, which uses an adaptable, stable, natural merge algorithm called Timsort. While searching, using the dictionary, the time complexity can be reduced to O (1), and the way the dictionary is implemented, is the use of the hash function, and hash lookup, then use the open addressing method.

Give two examples of Python simplicity

1. Sorting

In [1]: a_list=[22,33,11,9,77,22]
In [2]: A_list.sort ()
In [3]: a_listout[3]: [9, 11, 22, 22, 33, 77]

2. Find

In [5]: dict={'key1':'hh','key2' :key3':'II'}in [6]: dict[ ' Key3 ' ]out['II'

There may be nothing to see here, because it's just a simple usage. When you can implement a series of data structures and write the corresponding hybrid algorithms yourself, you can feel how much python is doing behind the times.

A ramble on search/Sort in Python

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.