Simple description of what is recursion? What is the use of? and use Java to implement a simple recursive program.

Source: Internet
Author: User

Answer:

1) recursion as an algorithm is widely used in programming language. Refers to the re-entry of functions/procedures/subroutines that invoke themselves directly or indirectly during operation.

2) Recursive algorithms are generally used to solve three types of problems:

A. The definition of the data is defined by recursion. (Fibonacci (Fibonacci) function)

B. The problem solution is implemented by recursive algorithm. Back

C. The structural form of the data is defined recursively. (Traversal of the tree, search of the graph)

3). This is an example of an arrangement in which the work is to sort and output all the elements of a string entered, for example: The parameter you give is "ABC" and the program outputs: ABC ACB BAC BCA Cab CBA A. The exit of the algorithm is: Low=high is now given only one of the permutation elements. B. The approximation process of the algorithm: first determine the first element of the arrangement, that is, the element represented by I in the loop, and then low+1 begin to reduce the permutation element, so continue until Low=high public class Foo {

public static void Main (string[] args) {

Permute ("abc");

}

public static void Permute (String str) {

char[] Strarray = Str.tochararray ();

Permute (strarray, 0, strarray.length–1);

}

public static void Permute (char[] list, int. Low, int.) {

int i;

if (low = = high) {

String cout = "";

for (i = 0; I <= high; i++)

cout + = List[i];

System.out.println (cout);

} else {

for (i = low, I <= high; i++) {

Char temp = List[low];

List[low] = List[i];

List[i] = temp;

Permute (list, low + 1, high);

temp = List[low];

List[low] = List[i];

List[i] = temp;

}

}

}

}

Simple description of what is recursion? What is the use of? and use Java to implement a simple recursive program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.