# What is recursion explain with example?

# What is an example of using recursive functions?

Answer .
\nLet's take the example of finding the factorial of a number (of a positive integer). \n.
\nThe factorial of N is \nN * (N-1) * (N-2) * (N-3) ... * 3 * 2 *1\n.
…\nIt is the product of all integers between that number (including that number) and 1.\n.
\nFor example, factorial 2 = 2*1 = 2\nfactorial 3 = 3*2*1 = 6\nfactorial 4 = 4*3*2*1= 24\n.
\nNow you define a recursive function Fac (N) as\nFac (N) = Fac (N-1) * N, with Fac(1) predefined as 1.\nThus, Fac(N-1) = Fac(N-2) * (N-1)\nand Fac(N-2) = Fac(N-3) * (N-2)\nand thus recursion takes over until such time fac(1) needs to be evaluated. We know the value of Fac(1) which is set as 1.\n.
\nThus we can evaluate Factorial(N) using recursion.

# What is recursion?

Read answer of question: "What is recursion?" .
Recursion in computer science is a way of 'Thinking About'and then 'Solving' problems. How does it look in reality when prog…rammed:int func1(int input1) { if(base condition) { return some finite value. } else { return func1(input2) //Function calls itself. } } So, to design a solution(algorithm) to any problem in such a waythat one function is having a call to itself inside a body andproblem is reduced in each successive self calls to that limit thatwe reach base condition that returns some result(finite value) andno further recursive calls are made further. This makes a recursivesolution and this way of solving the problem is called 'Recursion'.Examples of recursive problems:1.Check given string is apalindrome. E.g. 'RACECAR'. 2.Factorial of number. 3.Calculating nth term of 'Fibonnaci' series. E.g. if n = 4. Thenseries is 0,1,1,2,3 4.Binary Search 5.Greatest Common Divisor (GCD) calculation. Palindrome RecursiveAlgorithmstatic int depth; //GLOBAL CLASS VARIABLE public bool IsPalindrome(string PalindromeString) { depth++;//STANDARD if (depth PalindromeString[PalindromeString.Length - 1])//STANDARD- STOP CONDITION BASED ON CURRENT DATA MANIPULATION { //last result is propogated to last uppermost level of depth = 1without modification. At last depth we are at the result as the wehave already reduced the problem so that last level result becomesthe original result. //string is palindrome if current first and last characters areequal and substring left after taking first and last character is apalindrome. PalindromeString = PalindromeString.Substring(1,PalindromeString.Length - 2);//STANDARD DATA MANIPULATION CONDITIONIN FORM OF f(n) processing done on data = same processing done onf(n-1) * some post processing. return IsPalindrome(PalindromeString); //STANDARD - RECURSION CALLBASED ON ELSE OF STOP CONDITION OR IF PRE PRE PROCESSING IS DONETHROUGH DATA MANIPULATION STOP CONDITION THEN BASED ON ITS IF ORELSE CLAUSE. } else return false; } } Happy Programming :-) Himanshu Singh -noun Mathematics, Computers . the process of defining a function or calculating a number by therepeated application of an algorithm.

# Can anybody explain stack level functioning of recursion in c language exclusively?

Yes, any body can explain stack level functioning of recursion in Clanguage exclusively. ;-) Whenever we invoke a function, the return address is pushed ontothe call stack. Th…at return address remains on the call stack untilthe function returns at which point the address is popped from thestack and control passed to that address. In this way, functionscan always find their way back to their callers, even if thosefunctions invoke other functions, including themselves (recursivefunctions). As well as the return address, the formal arguments of the functionand the local variables of the function are also pushed onto thestack. Formal arguments are initialised by the actual argumentspassed by the caller, assigning the values of the actual argumentsto the formal arguments. If the formal argument is a pointervariable or reference, the address of the actual argument is passedinstead. In addition, the call stack is used by the exception handlingmechanism. When an exception is thrown by a function, the callstack "unwinds" (popping each function's stack frame) until asuitable handler is found.

# Examples using recursive procedure in the C computer programming language?

int factorial (int n) { if (n == 1) return 1; else return factorial (n - 1) * n; }

# What is recursive?

In computer programming, a function can call another function. If a function calls itself, it is said to be recursive. Doing this correctly can it quite simple to solve certai…n problems, that otherwise look very complicated. In math, a function is defined as recursive when it is defined in terms of itself. For example, the factorial of a number is the product of all numbers up to this number. Thus, the factorial of 4, written 4!, is equal to 1 x 2 x 3 x 4. A common definition for this function is as follows: 0! = 1, for all numbers "n" greater than zero, n! = n x (n-1)! For example, the factorial of 4 (which is 4 x 3 x 2 x 1) is equal to 4 times the factorial of 3 (which is 3 x 2 x 1).

# Write a example of recursion?

Following function calculates factorial of a number using recursion..
unsigned int factorial(unsigned int a) { if (a == 1) return 1; else { a *= factorial(a-1); … return a; } }.
recursion n. see recursion.

# Explain the term Recursion with example?

recursive definition of a function is defined in which the function is defined in terms of itself.here the fuction calls itself repetitively.

# What is recursiveness?

Assuming you mean "recursion", recursion is a function calling itself. A good example of when you would use recursion is for a directory walker. You would call the function, p…assing it a directory path. The function would call itself for all the directories in the directory you passed in. It would then do whatever processing it needed to on all the files in the directory.

# Write and explain recursive backtracking algorithm for n-queens?

This is not a question, this is your homework. For a start, read this: https://en.wikipedia.org/wiki/Eight_queens_puzzle

# Find an example or a recursive procedure and represent it as an iterative procedure?

int recursiveNFactorial (int n) { if (n < 2) return 1; if (n == 2) return n; else return n * recursiveNFactorial (n - 1); } int iterativeNFactorial (int n) { int re…sult = 2; if (n < 2) return 1; while (n > 2) result *= n--; return result; }

# What is an example of recursive pattern in expository writing?

DEFINITION OF RECURSION IN WRITING: .
When the speaker discusses a topic, then restates it using different words or symbolism. It is used to drive home a point and to give …special emphasis to the text..
EXAMPLE: I will succeed in this business. Lack of knowledge will not stop me; I will learn. Lack of money will not stop me; I will find financing. The presence of competition will not stop me; I will overcome. Lack of knowledge by my customers about my product will not stop me; I will expand my marketing reach. My business will not fail.

Answered

# Explain non-recursive and recursive algorithm for postorder traversal on binary tree?

Step 1:- select first root node (t), start travelsing left contin

Answered

In Uncategorized

# What is the purpose of a stack in implementing a recursive procedure Explain?

there is no a prior limit on the depth of nested recursive calls (that a recursive function may call itself any no. of times), we may need to save an arbitrary number of reg…ister values(return values of the recursive functions, that may be used latter to find the actual solution). These values must be restored in the reverse of the order in which they were saved, since in a nest of recursions the last subproblem to be entered is the first to be finished. This dictates the use of a stack , or ``last in, first out'' data structure, to save register values. We can extend the register-machine language to include a stack by adding two kinds of instructions: Values are placed on the stack using a save instruction and restored from the stack using a restore instruction. After a sequence of values has been save d on the stack, a sequence of restore s will retrieve these values in reverse order. Vishal Srivastava MCA, LU source : http://mitpress.mit.edu/sicp/full-text/sicp/book/node110.html

Answered

# What do you mean by recursive function explain with suitable example?

Type your answer here...

Answered

# What is recursion in c explain with the help of an example?

Recursion is the technique of a function calling itself, rather than iterating through the use of loops. The classic example of a recursive function is the computation of N Fa…ctorial... int nfact (int n) if (n 2) return n else return n * nfact (n - 1); If you call this with n 5, for instance, it will call itself an additional 3 times, so you will have 4 stack frames where the local value of n is 5, 4, 3, and 2. When you get to the last call, you unwind the stack frames, and the multiplication of 2, 3, 4, and 5 takes place. This example is for illustration only. It fails miserably with even small values of n (13, using 32-bit arithmetic) due to integer overflow, because N Factorial get large quickly.

Answered

# What is main difference between function and recursion explain with example?

Entirely different things, no point in comparison.