2, programming Abas note two algorithm

Truth and simplicity are the precious qualities of genius. — Stanislavsky”

I have always believed that programmers can never spend too much time on data structures and algorithms, which is the key to becoming a coder god.

Algorithms have a huge impact on software systems, and TOAD has a lot of experience with performance tuning. A slightly smaller algorithm will perform very well under high concurrency pressure.

In chapter two, the author brings us three questions and the thinking behind them. Toad summarises and describes them as briefly as possible.

Welcome to reprint, reprint please indicate the source: blog.csdn.net/notbaron/ar… \

1. A problem

As shown in Figure 1 below:

\

To solve this problem, the author introduces an algorithm that programmers use badly, which is dichotomy. Whether you live or work, dichotomy is probably a must-have tool for home travel.

2. Question 2

       

There are many solutions to this problem, but the most convenient is the one the author left and right. This scheme is also used by Ken Thompson to implement line movement in text editors. (Ken Thompson is the father of C and UNIX.)

Let’s think of the problem as an array ab and replace it with ba.

First take the inverse of a to get arb, then take the inverse of B to get ARbr, and finally take the inverse of ARbr to get BA. Flipping the code in both time and space is very funny, as shown in the master use.

 

 

Three (3) problem

 

Any way of thinking about the arrangement of all the letters in a word is doomed to failure.

The author’s method is to alphabetize the letters of a word, for example, the label of deposit is deiopst,

Similarly, the logo for dopiest is also deiopst.

Then see all the words sorted by identifier.

To find a word, simply get the identity and look it up in the order table.

 

 

4. Summary:

This chapter focuses on the basics to keep things simple.

Constant problem solving and reflection are required.