Sorting and underlying data structures

Source: Internet
Author: User

6 Sorts and 6 large basic data structures

This article from the bubble sort lifted, to select, Insert, Hill, Merge, fast row 6 kinds of classic array sorting in-depth analysis, and explain the relationship between them, so that you understand the key points, and the classical data structure vector, Stack, Queue, tree, Map, set to summarize, The bottom of its implementation of the analysis, to share to everyone, as each of the senior programmers should know the algorithm and sequencing, I wish everyone to embark on their "into Gold Road" in the morning.

Table of Contents: 1. Sorting algorithm 2. Data structure 3. Data reference 1. Sorting algorithm: A. Origin: The computer from the birth, in the simulation of the behavior of human intelligence, and the sequencing is from the daily life, the most classic bubble sort is derived from the water from the bottom of the bubble, the closer to the water, the larger the volume of blisters The bubbling sort idea that was born is to iterate through each element sequentially, and if the previous one is larger than the next, the position of the two is exchanged. Its disadvantages are two: the 1th each time the comparison will produce exchange element behavior, low efficiency; 2nd, the algorithm complexity is O (n^2) b. Optimization for disadvantage one: Select sort: That is, the index of the largest element is recorded each time, and then the element is exchanged; Insert sort: When the input order is high, by constructing an ordered array , and inserts new elements into the ordered array, completes the overall sorting, reduces the number of interaction of the elements, the disadvantage is not stable; Hill sort: Insert sort stability is too low, so by actively constructing ordered pairs (interval n, N/2, n/4...1 ordered pairs), to improve the "insert sort" of stability, is an improvement of the insertion sort. C. For the optimization of disadvantage two: merge sort: Adopt "divide and conquer the idea of algorithm", divide the input in two, respectively, through "parallel" thought to raise algorithm efficiency, the complexity is O (NLGN), but need extra arr[n] space, to merge; quick sort: Improvements to merge sort, In the case of no additional space, the array traversal, according to the selected elements of the comparison of the division, the small focus on the left, the large focus on the right side, respectively, the order of the two sides-the whole idea and the construction of the binary tree, its complexity is O (NLGN). D. Pseudo-code is summarized as follows:

2. Data structure: Instructional video reference to Stanford public class abstract programming, address http://open.163.com/special/opencourse/abstractions.html the main data structures are disassembled here, such as

It only gives a detailed explanation of its underlying structure, but when it comes to use, it also needs to provide some common interfaces for callers to use, such as size (), iterator ()/hasnext ()/next () x, Add ()/remove (), contain (), IsEmpty ( ), etc.; see Code Implementation Sharing Link: http://pan.baidu.com/s/1hsoReNa password: h9q0.

Sorting and underlying data structures

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.