💪 Start rolling it up! To make learning more interesting, in this article I will list computer science theories and some concepts, and use analogy and as few technical terms as possible to explain for you. The purpose of this is to allow you to quickly understand the computer and check for omissions.
👋If there is any improper interpretation of these concepts, please correct me in time.
Although these concepts can quickly help you understand, this is not the best way to learn. If you want to fully understand these concepts, read related books or papers.
1. Core concepts: data structure and algorithm
1.1 Recursion
For example, when you are sitting in the cinema and ready to watch a movie, the person who just came to the cinema asks which row you are sitting in. If you are lazy, ask the person in front of you, "Man, which row is your row? "You only need to know from the other person that his line number + 1 is the line number you are sitting on, but the guy in front of you did the same thing, and he asked the person in front of him. . . . . . By analogy, he asked until the first row, and he replied: "I am the first row!" From now on, the correct row number will be +1 until it is communicated to the buddy who just entered the cinema.
Don't do this in a movie theater, otherwise the people in the second or third row may be regarded as fools by the first row. . . . . . Because the person in the second row asks the person in the first row: "Man, which row do you sit in?" Imagine this scene. . . . . .
Let me give you a few pictures to let you understand what recursion is.
1.2 Big data
Suppose you have a garden, but the water pipe in , you need to get some buckets and sealing materials to solve this problem, but after a while, you find that the actual leak is much larger, and you need a plumber to take more Many tools to deal with, at the same time, you are still using buckets to drain water. After a while, you find that a huge underground stream has opened underground. You need to process several gallons of water per second.
At this time the bucket is useless, you need a new way to solve this problem, because the volume and speed of the water are increasing. In order to prevent floods in towns, you need to build a large dam, but this requires a lot of civil engineering expertise and complex control systems.
Big data describes large and complex data sets that cannot be managed using traditional data processing tools.
1.3 Data structure
Regarding data structure, every programmer should know
- Array https://en.wikipedia.org/wiki/Array_data_structure
- Tree https://en.wikipedia.org/wiki/Tree_%28data_structure%29
- Stack https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29
- Queue https://en.wikipedia.org/wiki/Queue_%28abstract_data_type%29
- Figure https://en.wikipedia.org/wiki/Graph_%28abstract_data_type%29
- Hash table https://en.wikipedia.org/wiki/Hash_table
- Linked list https://en.wikipedia.org/wiki/Linked_list
- Heap https://en.wikipedia.org/wiki/Heap_%28data_structure%29
2. Core Concept AI
2.1 Greedy algorithm
Imagine you are going on a hike, and your goal is to reach the highest peak as much as possible. Before you start, you already have a map, but the map shows thousands of roads, but you can’t evaluate each one, so throw After dropping the map, you start from a path that seems very simple. This method is selected based on your sensibility. It is a manifestation of greed and short-sightedness. You choose to take only the most inclined upward route.
But after the trip, the whole body is sore. You look at the map and find that there is a muddy creek next to it. Just step over it instead of going straight up.
Greedy algorithms will choose the best route at the moment, instead of re-considering evaluation options.
2.2 Hill climbing algorithm
This time you are going to climb another mountain, and you decide to find the way that will take you to the highest peak. But unfortunately, your map is lost, and the mountain is very foggy, what should you do? So in order to make the journey easier, you download an app that can track the way you walk and measure your current altitude. So every time you take the route is the route that can take you to the highest peak, but in the middle, you choose a different route, and this route can also take you to the highest peak.
2.3 Simulated annealing
In front of you is Mount Everest.
This is the biggest challenge you face. Your goal is to reach the top, but it is impractical to climb Mount Everest over and over again, so you only have one chance. You are now very cautious. You will not always climb up, but occasionally move to a lower point to explore other possible paths to reduce the chance of making mistakes. The higher you climb, the lower you move to explore. The lower the probability.
2.4 Dynamic programming
Father: Write "1+1+1+1+1+1+1+1=" on a piece of paper.
Father: What does that mean?
Son: After three seconds, the count is equal to 8.
Father: Write another "+1" on the left.
Father: How much is it now?
Son: I immediately determined it was 9!
Father: Why are you counting so fast now?
Son: Because you just added one!
Father: So you don't need to count again, but remember that the number just now is equal to 8!
2.5 The problem of P and NP
P vs NP is one of the most popular and important unsolved problems in the field of computer science.
Suppose I give you a multiplication problem, for example:
Q1:P = 7 * 17
The answer is 119. Is this easy to calculate? What if I reverse this question:
Q2: P * Q = 119 (Neither P nor Q can be 1 or 119)
If you don't see Q1 and you want to solve Q2, you may start from 2 and traverse until 118. So we still don't have an efficient algorithm to find a factor.
If I ask you, could P be 7? Can you easily verify the answer at this time? Of course you can, you only need to 119/7.
Multiplication is easy, but finding the primitive factors of a number is difficult.
So Q1 is a P (polynomial) problem. It is easy to solve because the computer can easily multiply any two numbers.
But Q2 is a NP (non-polynomial) problem. It is difficult to solve. It is easy for a computer to find the factor of 119, but what about 500-digit numbers? It is impossible for any computer now.
This is the most important part of this problem: Is the NP problem (decomposition) also P (multiplication), but we have not yet found an effective way to solve the NP problem? Or are humans too stupid? Imagine that there are machines or life that are much smarter than humans. They look at us as we look at ants. Our intelligence is too insignificant for them. Solving the P vs NP problem is like solving 1 + 1 for them!
So why is the P vs NP problem important? If we can prove that P=NP, it means that all NP problems can be easily solved in a reasonable computer time . We will be able to cure cancer (protein folding), crack codes (RSA), etc. This will change the world.
3. Core concept: Concurrency
Prospect summary: Suppose you are working as a secretary in a company. The work you do includes making calls, arranging meetings, writing documents, etc. You always need to stop the work at hand and do other tasks according to the priority of the task. ), every time the phone rings, you need to stop the work being processed.
3.1 Parallel
As the tasks accumulate, you can no longer cope with your work. Because there are too many writing tasks, you complain to your boss, and he is willing to hire someone to help you share the writing tasks.
Parallel allows two or more tasks to run at the same time, but the premise is that your CPU can support multi-processing capabilities, and people have only one CPU, so one mind can't do two purposes. This is not a bad thing. Sometimes single-threaded work efficiency is higher, and interruption (interrupted when learning) is the natural enemy of work, and this kind of overhead is too big.
So you share the writing task with the employee is a kind of 1618b43cb7ffc8 parallel.
The introduction of the concurrency concept has also caused many problems, such as the race condition .
3.2 Race conditions
Here I have to mention the bank transfer example that we are all familiar with:
- You have 1,000 yuan in your bank account.
- Someone transfers 500 yuan to you, and you withdraw 300 yuan from the ATM.
- Assuming that these two transactions are carried out at the same time, both transactions will see that your current balance is 1000 yuan (note that these are two transactions, and the two transactions were not visible to each other before, which is very important).
- Now, the first transaction adds 500 yuan to your account, and you now have 1,500 yuan. However, the second transaction saw that your account balance was still 1,000 yuan, and he deducted 300 yuan from 1,000 yuan to become 700 yuan.
- So your current account balance will become
700
yuan instead of1200
yuan, because the second transaction covers the first transaction. - This happens because the banking system is unaware of other ongoing transactions.
So, how should you handle this situation? Here are several solutions.
3.3 Mutually Exclusive
Now we use this method: As long as there is an ongoing transaction, the system will lock the account involved in the transaction. And the system will determine that the transfer start -> transfer completed is a complete transaction cycle.
So this time, when the first transaction occurs, your account will be locked and you can no longer withdraw money from your account until the first transaction is completed.
So does mutual exclusion solve the problem?
Although mutual exclusion can solve the problem of system data security, it does not conform to human perception. But no one wants to be rejected by the ATM every time there is an ongoing transaction.
So we need to modify the plan.
3.4 Semaphore
Binary semaphore
Now we need to set different priorities for different types of transactions. priority withdrawal request is higher than the priority of the bank transfer. So when you withdraw money from the ATM, the priority of this transaction is greater than the priority of the transfer to your account, so the transfer transaction will be suspended at this time, and the withdrawal transaction will take priority because it has a higher priority , After the withdrawal is successful, the transfer transaction resumes.
The binary semaphore is very simple, 1 = ongoing transaction, 0 = waiting.
Counting semaphore
The counting semaphore allows multiple processes to run at the same time.
Suppose you are a staff member of a swimming pool, there are 10 lockers, and each locker has a key. Every time you receive or distribute keys, you need to control the number of all keys. If all the storage is The cabinets are full, and everyone else must line up. Whenever someone finishes, he will hand the key to the first person in the queue.
3.5 Deadlock
Deadlock is another common problem in concurrency.
Let us take bank transfer as an example. Remember, as long as there is an ongoing transaction, access to the bank account will be locked out.
- Suppose you transfer 500 yuan to Aunt Zhang (to make Aunt Zhang happy), and at the same time Aunt Zhang transfers 1,000 yuan to you (to make up for your health).
- So Transaction A locked Aunt Zhang's account and deducted 1,000 yuan from her account.
- Transaction B locks your account and deducts 500 yuan from your account.
- Then, transaction A tries to access your account to add the 1,000 yuan she transferred to you.
- At the same time, transaction B tries to access Aunt Zhang's account to add the 500 yuan you transferred to her.
However, because the two transactions are not completed, neither transaction can access the locked account, causing both transactions to wait for the end of the other's transaction. This situation is a deadlock.
And why do boys take the initiative in the process of dating? If you do not take the initiative, you may be dead (deadlock).
4. Core Concept: Computer Security
4.1 Computer hacker
Computer hacking is similar to forcibly breaking into your house. There are several popular hacking techniques below.
Brute force attack
This approach is to try to use hundreds of different passwords. Experienced hackers will try the most commonly used passwords first.
Brute force attacks will try all possible passwords, usually first guessing commonly used passwords, such as "123456", "abcdef", etc.
I tried to use kali linux with a dedicated device to crack the neighbor’s WI-FI, but the password was only 000000.
Social engineering
This is a powerful technology! ! ! I would like to call it Network Pua! ! !
A couple just moved in next door. They are really nice and helpful. They often treat you to dinner. One day, you said that you would go on vacation for two weeks soon. They happily offered to take care of your dog. You left them a spare key. Since then, you have never heard anything about them.
The Social Engineering Society tricks users into revealing their private information.
There should be a picture here.
<img src="https://tva1.sinaimg.cn/large/008i3skNly1gvp44j0stej60ha0dkjrp02.jpg" alt="image-20211023120448543" style="zoom:50%;" />
Security breach
A security breach is a breach that a hacker can find in your home. For example, you may have left the window open.
Trojan Horse
The hacker pretended to be a plumber and asked you to open the door for him. He repaired your leaking pipe, but after he left, you found that your jewelry was missing.
Trojan horses are malicious software programs that pretend to be used and run malicious code in the background.
RootKit
Your door lock is stuck, you call the locksmith. He repaired your door lock and secretly copied another key.
Rootkit obtains computer administrator or root access rights through social engineering and other methods, and then pretends to be necessary files that are difficult to detect by anti-virus software.
DDos
This is the metaphor of a bookstore.
Suppose you have a bookstore, which can accommodate more than 200 people, and suddenly more than 200 people enter your bookstore one day, your bookstore is full, and you can’t drive them away because they don’t seem to know each other, and they It seems that everyone is really interested in buying books. Some people even ask you where the xxx book is, but only one person at the counter paid a few dollars.
People keep going in and out for hours, but you have sold less than 5 books. How long do you think your bookstore can last?
DDoS attempts to shut down sites or services through a large number of visitors.
4.2 Cryptography
Symmetric encryption
Suppose Lao Wang and Lao Liu want to send things to each other. To make sure that no one can see their things, they locked it up with a box. They made 2 identical (symmetrical) keys for the lock and met in advance to share the keys.
Asymmetric encryption
Sharing the key between two people works fine, but what if Lao Wang wants to exchange things with Lao Zhao, and I don't want Lao Liu to know what to do? Re-share a brand new key? So what if Lao Wang wants to exchange things with 10 different people? Do you want to eliminate the old king who solves the problem?
So Lao Wang came up with an absolute fashion idea: now Lao Wang only maintains one key (private key), she distributes the other key (public key) to his friends, anyone can encrypt, But only she has the key to open (decrypt). Now anyone can use the public key she sent to encrypt, and Pharaoh doesn't need to manage different keys for anyone.
5. Core concept: software development method
5.1 Waterfall development method
You need to figure out everything and record it, just like a waterfall, unless you start again, you can't return. Only after the current stage is completed, you can move on to the next stage.
<img src="https://tva1.sinaimg.cn/large/008i3skNly1gvphma9pgcj60wc0ocgo202.jpg" alt="image-20211023195137609" style="zoom:50%;" />
5.2 Agile development
This is the software development method adopted by most domestic software companies --- agile development .
At the beginning you figure out some things you need to sit on, and then as the development progresses, continue to improve, develop collaboration and adapt.
As most product managers or your leaders say: first make a version and then talk about .
5.3 Software development in the real world
Now you have graduated. You have written code that you think is more beautiful, and everything is perfect. Now I will introduce to you a cowboy code , which is a development method that the university professor did not teach you.
You may be wondering why you will not evaluate development events, please see the picture below
Summarize
In this article, I have compiled some common concepts in computer science for you, and used vivid examples to illustrate these concepts for you, hoping to lower the threshold for you to learn these contents.
Again, If you want to fully understand these concepts, read related books or papers .
Finally, I recommend my own Github , which contains a lot of hardcore articles, which will definitely help you.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。