In actual projects, what scenarios will recursion be used? How to Design recursion? In actual projects, what scenarios will recursion be used?
How to Design recursion?
Reply content:
In actual projects, what scenarios will recursion be used?
How to Design recursion?
The most common and easy-to-understand examples of recursive thinking are tree trees. Recursive thinking is also one of the most important basic ideas in software development, as @ _ yeshuai said. At the same time, there is no necessary relationship with the code, as you have commented on.
If a solution uses too deep recursive depth, does it mean this solution is not suitable for Recursive solutions?
In my opinion, the most important thing is to have this way of thinking, rather than writing recursive code. After all, recursion does affect efficiency.
Recursion is used in common tree structures, such as infinitus classification and folder traversal.
Recursion is certainly used.
With this questiontagFor example, you can try to usejsImplement the directory tree structure. There is no limit on the hierarchy. There may be only two layers, and there may be five layers, depending on the data.
Many algorithms must be implemented through recursion ~
For example, query all levels of subordinates under a supervisor, for example, query all level 2 and level 3 categories under a level 1 product category.
Remember to set the recursion termination conditions during recursion.
Trace is commonly used for hierarchical operations. For example, if this node is not configured, the data of the previous node is read.
Occasionally, such as infinitus classification and classification systems, such as the mall background and blog list
For example, to deeply copy a menu with an infinite number of js objects
How to design it depends on your specific application scenarios
You can view my notes for deep copying of js objects.
Https://segmentfault.com/n/1330000004855030
Occasionally used, not frequently used