## difference in return recursion call and just a recursion call

I am currently writing an inorder traversal for a binary search tree, while, the function I have wrote works correctly, I have a question I about how I am recursively calling this function.

**below is the function I have written and the output is currently correct using this implementation.**

if(root == nullptr) return; inorderDump(root->leftSubtree()); cout << root->value() << endl; inorderDump(root->rightSubtree());

My question is why don't these recursive calls need a return statement? The following function written exactly the same with the return statement does not work.

**below is an example of the same function while using the return statement and not getting the correct output.**

if(root == nullptr) return; return inorderDump(root->leftSubtree()); cout << root->value() << endl; return inorderDump(root->rightSubtree());

So I guess in short what I am trying to say is what is the difference between recursively calling a function with and without the return statement, and when do you chose one over the other? Thanks!

Below is the sample data I am using to test these recursive functions with.

16000 24507 64025 99756 114258 163016 196448 198668

In the second one the program just will travel through all the left subtrees until he find a null value, and do nothing else because the return statement make you go out from the function, so it wont travel through the right subtrees or print anything.

**Recursion and stack,** function pow ( x , n ) { if ( n == 1 ) { return x ; } else { return x * pow ( x , n - 1 ) ; } } alert Please note how the recursive variant is fundamentally different. So, the recursion reduces a function call to a simpler one, and then – to even more That limits the application of recursion, but it still remains very wide. Recursion: Time complexity of recursion can be found by finding the value of the nth recursive call in terms of the previous calls. Thus, finding the destination case in terms of the base case, and solving in terms of the base case gives us an idea of the time complexity of recursive equations. Please see Solving Recurrences for more details.

Recursion consists of calling the calling function from the called function.

In order for the recursive calling chain to end, there must be an exit condition.

The question posed suggests that a recursive call is dependent on returning something. Such is not the case. This is an understandable confusion brought on by the factorial and Fibonacci exercises.

In example 1 above, the recursive output is manifested by the output to std::cout.

In example 2, the double call to return is counter-productive -- because the second return can never be executed -- as the function's thread terminated with the first call. The fact that example 2 calls itself, does not mean that the second return will be executed.

There are recursive functions, the typical fibonacci problem being the best known, where the function makes two calls to subsequent layers. However, those two calls are called either as separate calls without a return or as an addition, with the return returning a sum.

Again, recursion does not require that a function return a value.

**What is the difference between a regular function call and a ,** The function call itself is no different - a function call will do the same thing in every pop the return address and store it; push the return values onto the stack; jump to In C++, can you pass subparts of an array to a function on a recursive call? and in a normal function call the variables are assigned just once in memory. I am currently writing an inorder traversal for a binary search tree, while, the function I have wrote works correctly, I have a question I about how I am recursively calling this function. below

I don't know where exactly is your confusion so I will throw a wider net here.

Recursion has nothing to to with returning and all to do with calling.

This is what recursion is:

... foo(...) { ... ... foo(...)... ... }

`foo`

is a function taking any number and kind of arguments and returning anything (including `void`

aka not returning anything). If somewhere inside `foo`

you make a call to `foo`

then `foo`

is recursive. That's it. This is recursion. A function calling itself.

Your function (the first one) has a `cout`

instruction, it will print the current node. `return`

would have no purpose.

The problem with the second version is simple: after the recursive call to the left side of the tree the function returns immediately, never reaching the `cout`

statement, thus never printing and never doing the right side of the tree recursion.

**Reading 14: Recursion,** A recursive function is defined in terms of base cases and recursive steps. We can define factorial in two different ways: @param word consisting only of letters A-Z or a-z * @return all subsequences of word, separated by commas, * where Recursion and iteration are just two different code structures with the same end result: Execution of a set of sequential instructions repeatedly. The emphasis of Iteration: The repeated execution of some groups of code statements in a program until a task is done. The emphasis of recursion: Here we solve the problem via the smaller sub-problems till we reach the trivial version of the problem i.e. base case.

**IC210: Functions V,** This idea can seem paradoxical when you're just getting started, so we'll go through an that in turn makes a separate call to the same function, but with different arguments. The base case is a way to return without making a recursive call. Summary – Recursion vs Iteration. This article discussed the difference between recursion and iteration. Both can be used to solve programming problems. The difference between recursion and iteration is that recursion is a mechanism to call a function within the same function and iteration it to execute a set of instructions repeatedly until the given condition is true.

**Python2 Tutorial: Recursive Functions,** Recursion is not only a fundamental feature of natural language, but of the human definition or a recursive function does: It is "running back" or returning to itself. If a function definition fulfils the condition of recursion, we call this function a Recursion, for all practical purposes, is when a function, method, subroutine, procedure, whatever you want to call it, calls itself. In C: void f () { int x = 0; x = x + 1; f (); } So long as anywhere in the function body a function calls itself, it's recursive.

**Python Tutorial: Recursive Functions,** Recursion is not only a fundamental feature of natural language, but of the human Usually, it is returning the return value of this function call. If a function definition satisfies the condition of recursion, we call this function a recursive function. To terminate the recursion, you must include a select statement in the definition of the function to force the function to return without giving a recursive call to itself. The absence of the select statement in the definition of a recursive function will let the function in infinite recursion once called.