Algorithms come from life and are used in life

Preface

This article does not describe the relationship between algorithm and code (that is, there is no algorithm dry goods), but only describes my personal connection and perception of the algorithm and life, but when the interviewer asked his own understanding of the algorithm during the interview It still helps.
Living in this ever-changing era, I feel more and more that many things in this world are insoluble, and that balance is the most difficult problem to deal with.

From life

how are you

A classic greedy algorithm life example:
suppose we have 1 yuan, 2 yuan, 5 yuan, 10 yuan, 20 yuan, 50 yuan, 100 yuan banknotes, the number of which are c1, c2, c5, c10, c20, c50, c100. We are now going to use this money to pay K yuan. What is the minimum bill?
Problem purpose:
to use the least banknotes to pay K yuan
Solution:
In life, it is obvious that we must first pay with the largest face value, if it is not enough, continue to use a smaller face value, and so on , And use 1 yuan to make up the rest.
Algorithm idea: It is very straightforward, every decision is made to choose the best solution of the current scheme.

Backtracking algorithm

Two classic backtracking algorithm movies:
A very famous movie "Butterfly Effect" was released in 2004. It tells the protagonist that in order to achieve his goals, he has been back to childhood through the method of backtracking, and at a critical fork in the road, make decisions.
There is also a movie "Edge of Tomorrow" released in 2014. It is also the protagonist who, in order to save the world, retraces the time and "scratch his proficiency" through continuous restarting of time. It is so skillful that it makes people feel distressed and finally succeeds.
Algorithm thought: In fact, it is essentially a kind of violent enumeration, try all solutions, either succeed or become benevolent. (The difference with violent enumeration is that backtracking can be pruned in some cases, so as to reduce the wrong way)

Dynamic algorithm

A classic dynamic programming case: (0-1 backpack problem)
For a group of indivisible items with different weights, we need to choose some to pack into the backpack. Under the premise of meeting the maximum weight limit of the backpack, the total weight of the items in the backpack is the largest What is the value?
I will not describe the specific solution of this problem here. If you are interested, you can Baidu by yourself. Here I will directly give the conclusion of the kinetic thinking.
Algorithm thought: Have a global view, the goal is only to achieve the final goal, every move must be efficient and expected.

For life

People often have many choices in their lives, so how to choose?
In the real world, there is no regret medicine. It is impossible to find the best suitable fork in the road through retrospective thinking; be
lazy and choose the path that is best for yourself at present. This is greedy thinking;
as for the rules, possess From the perspective of God, we know what our ultimate goal is, and we also know the consequences of various road choices and how to plan a long-term path for ourselves to achieve this goal, but often most of us fail to achieve the goal because they are all down. Midway.

Do you really have no solution if you don't have a solution?

The problem of x 2 = -1 is indeed an unsolvable problem in junior high school (real number field), but it is a problem solved in high school (paraphrase field) from another perspective. Perhaps the unsolvable problem itself is not absolutely unsolvable. Sometimes the boat may not be straight to the end of the bridge, and there may not be a road when the car reaches the front of the mountain.

A common unsolvable case at work

Mentor assigned me a feature, and I found that one of the features cannot be achieved with my current ability.
Maybe this is an unsolvable problem, but it's actually not that simple.
First of all, I have to use retrospective thinking to try every solution idea as much as possible, and then finally confirm that I really can't do it. Later, through communication, I found that choosing greedy thinking to give up this function is at least the current optimal solution. As for my ability to improve in the future, I will look back at this "unsolvable" problem, maybe it is no longer unsolvable.

A common unsolvable case in life

One of the most common unsolvable topics in the relationship between men and women is that I don’t like you. If I don’t like it, I don’t like it. There is no reason why I
encounter this kind of problem. The solution for some people is that I am not convinced. I have to grasp all possible hopes. Live, I have tried it all, can I really find a solution in this way? Not necessarily, just like x 2 = -1 in the real number domain, you might end up as a "licking dog".
The solution of other people is to give up if there is no solution. I have to say that in many cases this is indeed the current optimal solution.
And some people have discovered the essence of unsolvable, and enter a new level by changing the dressing to solve unsolved problems.

Conclusion

These three algorithm ideas have their own advantages and disadvantages in life:
retrospective thinking embodies a state of mind that does not give up. On the positive side, I have tried my best and have a clear conscience, but many times unsolved problems use this kind of thinking to deal with problems. It will only be the physical and mental exhaustion of losing the wife and breaking down; the greedy thought reflects a kind of mental state of stopping loss in time. Since this question is unsolvable, then I will give it up directly. At least this choice is for the current self. It is said to be the best solution, but this kind of thinking will lead to a very low vision, and no longer have a global view, how can I talk about achieving my ultimate goal; the dynamic thinking reflects a mental state of a global view, which is undoubtedly the best Choose a plan, but in order to often most people will not choose it, because the person who travels a hundred miles is half ninety, and many people can't even reach the ninety. The final outcome is probably not as good as the outcome of greedy thinking.
Perhaps, which algorithm idea to choose has become an unsolvable problem. As mentioned in the preface, many things in the world are unsolvable, and balance is the most difficult problem to deal with. No problem is solved without a solution. After all, life is still the most important thing. Therefore, from the perspective of life, it may be the best solution for no problem to be solved without thinking about it and not trying to solve it!

Guess you like

Origin blog.csdn.net/asd0356/article/details/108690225