"Python Learning notes-data structures and algorithms" merge sort

Source: Internet
Author: User

"Merge Sort" Here we use recursive algorithm to keep the list in two, base case is no element in the list or only one element, because this sub-list is bound to be a positive sequence, and then gradually merge the two sorted sub-list into a new positive sequence table, until all the elements sorted.

"This is a process from the bottom up (bottom-up)

Divides the list from the middle into two sub-lists until it reaches the bottom, with only one element in the sub-list

  

Then, the two sub-lists are merged from bottom to top, and all the elements of the two sub-lists are sorted to form a new list.

  

"Implementation of merge Sort"

  

You can use print to see what you've done with each step.

"Performance Analysis"

The time complexity is O (n*log N), but the merging process requires extra space and the space complexity is O (n).

"Python Learning notes-data structures and algorithms" merge sort

Related Article

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.