Recursive
featuresRecursive algorithm is a direct or indirect process to invoke its own algorithm. In the computer programming, the recursive algorithm is very effective to solve a large class of problems, it often makes the description of the algorithm concise and easy to understand. The recursive algorithm solves the problem characteristic: (1) recursion is to call itself in a procedure or function. (2) When using a recursive strategy, there must be a definite recursive end condition called a recursive exit. (3) Recursive algorithm is usually very concise, but the recursive algorithm is less efficient in solving problems. Therefore, the recursive algorithm is generally not advocated for the design of the program. (4) in the process of recursive invocation, the system opens up a stack for each layer's return point, local quantity and so on to store. Too many recursion times can cause stack overflow and so on. Therefore, the recursive algorithm is generally not advocated for the design of the program.RequirementsRecursive algorithms generally embody the "repetition" of three requirements: first, each call is scaled down (usually halved), and the second is a close connection between two repetitions, the previous time to prepare for the next time (usually the previous output as the last input) Thirdly, when the scale of the problem is very small, it must be given directly to answer instead of recursive call, so each recursive call is conditional (the size does not reach a direct solution), unconditional recursive call will become a dead loop and can not end normally. Example: 2 points find an existing list primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97], request Wait for the quickest way to find out at
defFind (ARGS1,ARGS2): Coun=Len (ARGS1) Mid= Int (COUN/2) ifCoun >= 1: ifArgs1[mid] >Args2:find (ARGS1[:MID],ARGS2)elifArgs1[mid] <Args2:find (ARGS1[MID:],ARGS2)Else: Print('I found it! ') Else: Print('didn't find') Primes= [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]find (primes,91g
Python Path (vii)-recursive algorithm