LeetCode笔记之Resursion

  1. Tail resursion:
    在这里插入图片描述

  2. Divide and Conquer:
    LeetCode笔记之Resursion_第1张图片
    LeetCode笔记之Resursion_第2张图片
    典型问题是mergesort

  3. Backtracking:
    LeetCode笔记之Resursion_第3张图片
    Conceptually, one can imagine the procedure of backtracking as the tree traversal. Starting from the root node, one sets out to search for solutions that are located at the leaf nodes. Each intermediate node represents a partial candidate solution that could potentially lead us to a final valid solution. At each node, we would fan out to move one step further to the final solution, i.e. we iterate the child nodes of the current node. Once we can determine if a certain node cannot possibly lead to a valid solution, we abandon the current node and backtrack to its parent node to explore other possibilities. It is due to this backtracking behaviour, the backtracking algorithms are often much faster than the brute-force search algorithm, since it eliminates many unnecessary exploration.

典型问题:N-queens

典型代码结构:
LeetCode笔记之Resursion_第4张图片
注意点:LeetCode笔记之Resursion_第5张图片
4. Unfold resursion:
Recursion could be an elegant and intuitive solution, when applied properly. Nevertheless, sometimes, one might have to convert a recursive algorithm to iterative one for various reasons.
LeetCode笔记之Resursion_第6张图片
The good news is that we can always convert a recursion to iteration. In order to do so, in general, we use a data structure of stack or queue, which replaces the role of the system call stack during the process of recursion.

你可能感兴趣的:(leetcode,算法,职场和发展)