当前位置:网站首页>Difference between backtracking and recursion
Difference between backtracking and recursion
2022-07-06 06:26:00 【jq_ ninety-eight】
Look at the data structure recently , It is found that many recursion and backtracking problems are used , I really don't know the difference between the two , I checked some information recently , Let's summarize .
In order to describe a certain state of the problem , The previous state of this state must be used , And describe the previous state , You must use the previous state of the previous state …… This method of defining yourself by yourself , Called recursive definition . In the form of f(n) = n*f(n-1), if n=0,f(n)=1.
Starting from one possibility of the problem , Search for all the possibilities that can be achieved from this situation , When this road comes to ” At the end of “ When , Go back to the starting point , From another possibility , Continue to search . This continuous ” to flash back “ The way to find the solution , Referred to as ” backtracking “.
Recursion is an algorithm structure , Recursion will appear in the subroutine, calling itself or indirectly calling itself . The most direct recursive application is to calculate the factorial of continuous numbers , The law of calculation :n!=(n-1)!*n.
Observe the law of factorial calculation , The result of the former number formation can be directly applied to the calculation of the latter number formation .
int fac(int n)
if(n==1)
return n;
else
return n*fac(n-1);
Backtracking is an algorithmic idea , It can be implemented recursively . Generally speaking, backtracking is a kind of Temptation , Similar to exhaustive , But backtracking has “ prune ” function , For example, the summation problem . Given 7 A digital ,1 2 3 4 5 6 7 Sum equals 7 The combination of , Search from small to large , choice 1+2+3+4 =10>7, Already exceeded 7, After that 5 6 7 There's no need to continue , This is an optimization of the search process . If there is anything unclear, you can have a look 8 queens problem .
Link to the original text :https://blog.csdn.net/u014772862/article/details/51789015
边栏推荐
- JDBC requset corresponding content and function introduction
- G - Supermarket
- G - Supermarket
- MySQL之基础知识
- Play video with Tencent video plug-in in uni app
- Oscp raven2 target penetration process
- [mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
- Technology sharing | common interface protocol analysis
- 联合索引的左匹配原则
- 自定义指定路由上的Gateway过滤器工厂
猜你喜欢

浅谈专项测试之弱网络测试

Defense (greed), FBI tree (binary tree)

Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
![[postman] collections - run the imported data file of the configuration](/img/85/7ac9976fb09c465c88f376b2446517.png)
[postman] collections - run the imported data file of the configuration

基于JEECG-BOOT的list页面的地址栏参数传递

LeetCode 731. My schedule II

黑猫带你学UFS协议第4篇:UFS协议栈详解

G - Supermarket

JDBC Requset 对应内容及功能介绍

技术分享 | 常见接口协议解析
随机推荐
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
调用链监控Zipkin、sleuth搭建与整合
Set the print page style by modifying style
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
基於JEECG-BOOT的list頁面的地址欄參數傳遞
Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
模拟卷Leetcode【普通】1447. 最简分数
生物医学英文合同翻译,关于词汇翻译的特点
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
How to extract login cookies when JMeter performs interface testing
Data type of MySQL
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
SourceInsight Chinese garbled
Construction and integration of Zipkin and sleuth for call chain monitoring
模拟卷Leetcode【普通】1062. 最长重复子串
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
MFC dynamically creates dialog boxes and changes the size and position of controls
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order