[Classic algorithm] Enumeration method

Understand enumeration method

The idea of ​​the enumeration method is actually to try every possible solution and adopt it if the conditions are met. Otherwise, continue the enumeration without duplication or omission. For example, to find all the names that meet the conditions from the class list in a certain order, the enumeration method is used.

We often use enumeration methods in life. For example, when you take a bunch of keys to open a room door, because there are no marks on the keys, you can only try them one by one. Finally, you find the key that matches the door lock and open the door.

What's the key to using enumeration?

Let's imagine that if we let the computer find the key corresponding to the room from a keychain through enumeration, what information do we need to tell the computer?

We want to tell the computer that if the key can open the room door, there is no need to try anymore. This is a key factor in the enumeration method: The conditions for determining the correct solution. The judgment condition in this question is whether the key can open the room door.

Another key factor in the enumeration method is:Determine the scope of the enumeration. The computer needs to know how many keys there are so it knows the maximum number of attempts.

expand:

The algorithm of enumeration method is very simple and works well when used locally. However, when the scale of the problem becomes larger and the amount of calculation becomes larger, the execution speed will slow down. For example, if we want to find a certain word, such as zoo, from an English dictionary, if we do not search according to the first letter, but start from the first English word in the dictionary until we find zoo, then the computer will execute The efficiency is not high.

Think about it:

When we continuously enter the wrong password to unlock the phone, the phone will prompt that if we enter the wrong password again, we will have to wait for a period of time before we can unlock it again. Why?

The mobile phone settings will be deactivated if you continuously enter the wrong password. In fact, this is to protect property security.

If you don't set it up like this, then anyone can finally open your phone by enumerating all possible passwords one by one. In addition to mobile phones and tablets, when we log in to websites, apps or enter passwords at ATM machines, the system will limit the number of password entries. In fact, this is to prevent criminals from using the idea of ​​​​enumeration to crack passwords.

Guess you like

Origin blog.csdn.net/weixin_41989013/article/details/133784626