ArticleDirectory
- Recursion
- Recursive Application
Recursion
Recursion is implemented as a kindAlgorithmInProgramIt is widely used in design languages. it refers to the re-import phenomenon that functions, processes, and subprograms call themselves directly or indirectly during operation. recursion is an important concept in computer science. The recursive method is an effective method in programming. Writing a program using recursion can make the program concise and clear ..
General Definition
The Programming Technique of program calling itself is called recursion ).
A process or function has a method that calls itself directly or indirectly in its definition or description, it usually converts a large and complex problem into a small problem similar to the original problem to solve it, recursive strategies can describe the repeated computations required for the problem-solving process with only a small number of programs, greatly reducing the numberCodeQuantity. The ability to recursion lies in the use of limited statements to define an infinite set of objects. In general, recursion requires boundary conditions, recursive forward segments, and recursive return segments. If the boundary condition is not met, recursive advances. If the boundary condition is met, recursive returns.
Note:
(1) recursion is to call itself in a process or function;
(2) When using a recursive policy, there must be a clear recursive termination condition called the recursive exit.
Recursive Application
Recursive Algorithms are generally used to solve three types of problems:
(1) data is defined recursively. (Fibonacci function)
(2) The problem solution is implemented by recursive algorithms. (Backtracking)
(3) The data structure is defined by recursion. (Tree traversal, Graph Search)
Disadvantages of recursion:
Recursive Algorithms are less efficient in solving problems. During the recursive call process, the system opens a stack for storing the return point and local volume of each layer.
Too many recursion times may cause stack overflow.
Protected Void Button#click ( Object Sender, eventargs e) {sqldataadapter da = New Sqldataadapter (" Select * from [Table] ", Configurationmanager. connectionstrings [" Testconnectionstring "]. Connectionstring); datatable dt = New Datatable (" Tab1 "); Da. Fill (DT); xmldocument XD = New Xmldocument (); xmldeclaration xdl = XD. createxmldeclaration (" 1.0 "," UTF-8 ", Null ); XD. appendchild (xdl); xmlelement Xe = XD. createelement (" Root "); XE = xmlelementcreate (DT ," ", XD, Xe); XD. appendchild (xe ); Try {XD. Save (" D: // xmlcerate. xml "); Response. Write (" OK ");} Catch (Exception ee) {response. Write (EE. Message );}} Private Xmlelement xmlelementcreate (datatable DT, String Parentcode, xmldocument XD, xmlelement xee ){ String Strparentcode =" "; If (Parentcode. Trim (). Length = 0) strparentcode =" Parentcode is null "; Else Strparentcode =" Parentcode =' "+ Parentcode +" ' "; Datarow [] DR = DT. Select (strparentcode ); For (Int I = 0; I <dr. length; I ++) {xmlelement Xe = XD. createelement (" C "+ Dr [I] [" Code "]. Tostring (). Replace (" . "," "); Xmlattribute xacode = XD. createattribute (" Code "); Xacode. value = Dr [I] [" Code "]. Tostring (); Xe. Attributes. append (xacode); xmlattribute xaname = XD. createattribute (" Name "); Xaname. value = Dr [I] [" Name "]. Tostring (); Xe. Attributes. append (xaname); XE = xmlelementcreate (DT, Dr [I] [" Code "]. Tostring (), XD, Xe); xee. appendchild (xe );} Return Xee ;}