I haven't updated my blog for a long time. One reason is that the technologies used in the projects I developed are all old technologies, and the knowledge I came into contact with is all industry logic processes, so I just made a summary and didn't share it. Another reason is that I am currently relearning C++ language and some basic computer knowledge (algorithms, etc.). The following code is C++ code. Let’s get straight to the point. Basic Programming Algorithms (I) Basic Programming Algorithms (II) Basic Programming Algorithms (III) Binary Search Also called binary search. Conditions of use: ordered set. Algorithm idea: first determine the range (interval) where the record to be searched is located, and then gradually narrow the range until it is found or not found. The key point is to compare the keyword recorded in the middle position with the given value. If it is greater than the given value (here we assume that the set is arranged from small to large), then the interval range can be narrowed (start of the set --> previous position in the middle), and the keyword recorded in the middle position of the interval is compared with the given value, and the cycle is repeated until the position is found or not found. Example programming: Here is an integer data int a[10]={1,5,10,13,17,23,65,77,81,93}; (1) This is recursion (thanks to fellow user zdd for pointing out the error in the judgment condition here, which should be changed to if(min>max))
(2) Non-recursive
Performance analysis: time complexity O(logn) Insertion Sort Conditions of use: Collections of comparable sizes. Algorithm idea: insert a record into the sorted ordered sequence to get a new ordered sequence with the number of records increased by 1. The record to be inserted is compared with the sorted sequence in turn. If the sequence number is greater than the record to be inserted, the sequence is moved back one position until a sequence smaller than the record to be inserted is found. At this time, it is inserted into the next position of the sequence, and the above operation is repeated until all positions are inserted. Example programming: int b[10]={77,1,65,13,81,93,10,5,23,17} to sort it
Performance analysis: time complexity O (n^2) Binary Insertion Sort Conditions of use: Collections of comparable sizes. Algorithm idea: The basic idea is similar to that of simple insertion sort. The only difference is to find the insertion position. Simple insertion sort uses sequential comparison. Binary insertion sort is improved here, and the sequential search is improved into a binary search. Example programming: int b[10]={77,1,65,13,81,93,10,5,23,17} to sort it
Performance analysis: time complexity O (n^2) Although the time complexity here is the same as that of simple insertion sort, the number of comparisons used to find the insertion position is significantly reduced. Original text: http://www.cnblogs.com/couhujia/archive/2011/03/23/1991110.html |
<<: Heap sort algorithm popularization tutorial
>>: Easily master the basic programming algorithms (Part 2)
Google Talk, which was once very popular among pr...
First instance: Yu Qun Second trial: Suo Yingxing...
There is a secret to doing SEO: "Small sites...
There are two aspects of concerns about Sharp TVs...
Germany's strong sales momentum for electric ...
“Mobile Taobao” has finally been renamed “Taobao”...
In July 2017, Baidu CEO Robin Li sat in a self-dr...
Guizhou Sky Eye is the nickname of the 500-meter ...
I recently spent a month polishing a traffic gene...
Huawei, a manufacturer that does not make cars, h...
After experiencing nine consecutive declines, new...
How much is the quote for educational production ...
With the popularity of the TV series "Alley ...
I don't know if you have ever wondered about ...
SEO optimization is a complex system project. It ...