O
O
Oleg Obodin2017-05-22 13:42:58
JavaScript
Oleg Obodin, 2017-05-22 13:42:58

Whether correctly I paint process of a recursion?

Actually here:
8e66fa96db.jpg
I ask you to direct me on the path of truth, if I am mistaken somewhere, but not by a decision, but by a tip.
And yet, how to learn to solve problems using recursion without writing the whole process on a piece of paper? Probably, at the initial level, in any way? I solved the problem somehow intuitively, which is not very pleasing. Well, not quite right.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2017-05-22
@saintpat

call the function and pass it 2 - start, 6 - end, 2 - step
condition check 2 < 6, yes, return 2 + call the function, pass it 4 - start (2 + step), 6 - end, 2 - step
check condition 4 < 6, yes, return 4 + call the function, pass it 6 - start (4 + step), 6 - end, 2 - step
check condition 6 < 6, no, return 6
total: 2 + 4 + 6 = 12
They say "to know recursion, you need to know recursion"
With experience, understanding will come, write a couple of times and you will understand, the main condition for the exit is not to forget.

V
Vitaly, 2017-05-22
@vshvydky

Have you tried turning on the debugger? and step by step to get an understanding?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question