Current location - Training Enrollment Network - Mathematics courses - How to brush questions with algorithms
How to brush questions with algorithms
1, original title

I feel that the probability of the original question is quite large, especially the 66 questions of the sword refers to the offer. Don't underestimate these 66 questions. Almost all algorithm types are included in these dozens of problems. There are many problems in common data structures, operation methods and common algorithm ideas.

If I can fully understand the optimal solutions of these dozens of problems, I think I have actually formed a basic algorithm thinking.

In addition, the original title of leetcode is also very common, because LC itself has a large number of questions, and the original title inside is not to test you, but to test the quality of your brush questions.

After all, the interviewers of those big companies are not fools, knowing that you will brush the questions on a large scale before the interview. Therefore, it is most important to fully understand the brush questions.

2, the adaptability problem

The problem of adaptation is obvious. Most of the adaptation problems need to be solved by finding the processing idea from the basic algorithm principle, and then optimizing the performance in combination with the actual problem.

Remember here that normal algorithm checking will not deliberately make things difficult for you (normal situation), nor will it give you too much time to think and code.

So don't think too complicated when you encounter the adaptation problem, try to figure out what its algorithm thinking is. what can I say? See the essence through the phenomenon. The adaptation questions I summarized have the following ideas:

1) new data structure. For example, the adaptation of the most common sorting algorithm, sorting numbers in the past, sorting linked lists now and so on. It may be more difficult to encounter custom data structures. But the essence of the algorithm will not change.

2) Algorithm type adaptation.

What I want to talk about here is a relatively large range, such as dynamic programming, greedy algorithm, recursion, backtracking and divide and conquer, and so on. This algorithm is a large-scale adaptation, and the same routine is difficult to solve the problem.

The key to this kind of problem is to understand the core of the algorithm first. For example, the state equation of dynamic programming, the local optimal situation of greedy algorithm, the boundary judgment of recursive backtracking, the sub-problem division of divide and conquer and so on. This type is really difficult to master. How to master it? Let's make some feelings for each type.

3) Add application background.

This kind of problem seems not difficult, but it is difficult to understand the background of the application problem. We need to understand the meaning of the problem, and then consider the appropriate data structure and processing algorithm. There is mathematical modeling thinking, and it is necessary to eliminate a bunch of useless information and screen out effective information before choosing the correct algorithm.

3. Innovation issues

This kind of question examines your extended thinking. If the above question examines the depth of your thinking, then this question is to examine the breadth of the algorithm. Maybe I have never seen this type when I read the topic. But the algorithm itself is actually to let the computer replace the human brain for highly repetitive calculations.

First of all, you need to think about how to calculate this problem, and then switch to the computer, and what problems will appear (space and time problems, running efficiency, code redundancy, etc.). ), and then you want to solve these problems through classical algorithm principles.

1, problem classification

According to my personal habits, I like to brush wildly according to one type and then brush another type. General common algorithm types can be divided into:

Array, linked list

Contains a series of operations such as basic sorting algorithm, method of bisection and linked list.

Stack, queue, heap

Use stacks and queues to realize the use of each other and the heap.

Binary tree and graph

Mainly ergodic algorithm and node calculation:

Four traversal methods of binary tree, breadth-first traversal (BFS) and breadth-first traversal (DFS), the distance from node to node and so on.

Hash Table

It is very simple to use the template or function that comes with the standard library, and it is usually combined with other data structures to improve the time complexity.

String operation

There are many operations on strings, which can be regarded as array operations in essence. In addition, some matching of strings and the algorithm of finding strings are still worth thinking about. KMP, carriage and so on.

recursion

Focus on mastering the boundary judgment conditions.

recall

Focus on mastering the boundary judgment conditions.

divide and rule

The key point is how to solve molecular problems.

Dynamic programming

There are too many problems. We can understand different state equations from the first-order dp to the second-order dp.

Greed and others

This is easy to understand, laugh when you meet a greedy question.

2, high frequency hot spot multi-brush

Not much to say, Leetcode hot topic HOT 100. You deserve it.

If you don't know how to brush, you might as well brush first. There are not so many shortcuts to brushing a question. Only by persisting can we form our own way of thinking and study habits.

My suggestion is to brush by type first, and brush each type ten or twenty times. Then mix them up and sort them according to the heat of the algorithm, and then check the missing and fill in the gaps again.

3. Overview of views

Many students brush a lot of questions at once, and then look at the questions they have done and you will find that you have forgotten a lot. Maybe everyone is like this. I think it's because I was too impatient when I brushed the questions. I probably passed after I understood them, or the types were too miscellaneous to leave an impression.

My favorite way is to occasionally look at the questions I have done, just look at the questions and think about ideas, and then draw a step evolution, so I won't knock carefully if I don't have time. This can enhance your thinking and memory, and what you understood before can be recalled quickly.