First, the experience of the idea of the dichotomy
1. The two-cent method is a typical example of the use of the divide-and-conquer strategy, also known as binary, which takes full advantage of the order relationship between elements and is a highly efficient method of finding. Two methods are recursive and non-recursive to realize the binary algorithm.
2. Basic idea: divide n elements into roughly the same two halves, take A[N/2] and compare with X. If X=A[N/2], the x is found, the algorithm terminates, and if A<[N/2], only the left half of the array a continues to search for x, and if X>A[N/2], only the right half of the array continues to search for X.
3. Code implementation:
intBinarySearch (Type a[],ConstType&x,intN) { intleft =0;intright = N1; while(left<=Right ) { intMiddle = (left + right)/2; if(X==a[middle])returnMiddle; if(x >= a[middle]) left = middle +1; Elseright = Middle-1; } return-1;}
4. Analysis of Time complexity:
In this process, the size of the array to be searched is reduced by half for each time the while loop is executed. Therefore, in the worst case, the while loop is executed O (Logn) times. The loop in vivo operation requires O (1) time, so the computational time complexity of the entire algorithm in the worst case is O (logn).
5. Advantages: Improve the search efficiency, reduce the complexity of time, easy to achieve
Cons: With certain limitations, only applicable to sequential arrays
Second, about pairing programming
Pairing programming makes it easier for us to find our own mistakes in programming, so-called "lookers, Onlooker sees most," and sometimes the code you write is not easy to find errors. With the partner knot pair process, there are problems two people together to smooth the implementation of the code, quickly find out the errors found therein. Some confusing questions. It is easier to find the answer for two of people to discuss together. Pairing programming also makes us understand some other people's ideas about code, learn a lot of things, improve the efficiency of programming, broaden their own problem-solving thinking.
Understanding of dichotomy and pairing programming