A brief discussion on the recursion of data structure and algorithm analysis

Source: Internet
Author: User
Tags mathematical functions

1. When a function is defined by itself, it is called recursion. C allows the function to be recursive. But the important thing is that C provides only an attempt to follow the idea of recursion. Not all mathematical recursive functions can be implemented effectively (or correctly) by recursive simulations of c.

int int N) {    if0)    {        return0;    }     Else     {        return311;    }}

In the above example, the computer will repeatedly call bad (1) in order to solve its value. Finally, the computer system will occupy a full space, the program crashes.

Note: In fact, recursive calls are not different from other calls on processing. Trace pending function calls, which have already started but are waiting for a recursive call to complete, and the logging of variables in them is done automatically by the computer.

2. Four basic rules of recursion.

(1) The benchmark situation.

You must always have certain benchmarks, which can be solved without recursion.

(2) Continuous advancement.

For situations where recursive solutions are required, recursive calls must always be able to move in the direction of the resulting baseline case.

(3) Design rules.

Assume that all recursive calls can be run. This is an important rule because it means that when designing a recursive program, it is generally not necessary to know the details of the overhead management, and the computer can work out the complex details without having to trace a large number of recursive calls to the view.

(4) The principle of synthetic benefit.

Do not perform repetitive work in different recursive invocations when solving the same instance of a problem.

For example, the idea of using recursive returns to calculate values for simple mathematical functions such as the Fibonacci sequence is generally not a good idea.

A brief discussion on the recursion of data structure and algorithm analysis

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.