You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
751 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

https://www.cnblogs.com/smuxiaolei/p/7505391.html
递归是一种算法结构,回溯是一种算法思想
一个递归就是在函数中调用函数本身来解决问题
回溯就是通过不同的尝试来生成问题的解有点类似于穷举但是和穷举不同的是回溯会“剪枝”意思就是对已经知道错误的结果没必要再枚举接下来的答案了比如一个有序数列1,2,3,4,5我要找和为5的所有集合从前往后搜索我选了1然后2然后选3 的时候发现和已经大于预期那么4,5肯定也不行这就是一种对搜索过程的优化
回溯搜索是深度优先搜索DFS的一种
对于某一个搜索树来说搜索树是起记录路径和状态判断的作用回溯和DFS其主要的区别是回溯法在求解过程中不保留完整的树结构而深度优先搜索则记下完整的搜索树。
为了减少存储空间,在深度优先搜索中,用标志的方法记录访问过的状态,这种处理方法使得深度优先搜索法与回溯法没什么区别了。