Any good recursive tutorials? Python

I wonder if anyone can point me to a good recursion tutorial. I'm a little rusty as I found out about this in my Data Structures class in the first semester. Would like to refresh my recursion ... any help?

+3
source share
2 answers

Consider this one .

More seriously ...

Recursion is a way to solve problems that have a well-defined underlying case (or cases, btu, I make it simple here.)

As an example, the often mentioned factor problem is a big one.

What does factorial do? Let's look at some examples:

factorial(0) = 1
factorial(1) = 1
factorial(2) = 2
factorial(3) = 6
factorial(4) = 24

- , , , ( ) 0. 0 1. ( , .)

, . , , ( , .) .

def factorial(x):
    if x == 0:            # this is our base case
        return 1          # and this is what we do when we see it
    else:                 # this is what we do with all other numbers
        return x * factorial(x-1)

,

  • .
  • - .
  • , , ( !)

    function:
        if base case: 
            this
        else: 
            something + function(something closer to the base case)
    

- , Google .

+11

MIT .

4 .

+5

Source: https://habr.com/ru/post/1755647/


All Articles