Two concepts were proposed before the start: time complexity and space complexity.
Time Complexity refers to the correspondence between the running time of the algorithm and the problem scale.
Time complexity is represented by T (n) = 0 (f (n). 0 indicates the growth of Algorithm Execution time and the increase of f (n) as the problem scale n increases.
The same length rate. If a code without loops does not change the execution frequency of the algorithm, it is recorded as 0 (1 ). When the algorithm has a repeat
Loop, then the execution frequency will linearly increase by 0 (n * n)... and so on.
This expression is very abstract. Here are two examples:
1,
I = n;
X = 0;
While (x <I)
{
X = x + 1; // This is a loop with the time complexity T (n) = 0 (n)
}
2,
Int re = 0;
For (int I = 0; I <n; I ++)
{
For (int k = 0; k <n; k ++)
{
Re = re + (I * j); // This is a dual loop, and the time complexity is T (n) = 0 (n * n)
}
}
Space complexity refers to the amount of storage space temporarily occupied during the running of the algorithm. The advantages and disadvantages of an algorithm mainly refer to the algorithm
The execution time and the storage space occupied are measured. The algorithm execution time is not measured by Algorithm Execution.
Absolute time is used for computing, because an algorithm takes different time to execute on different machines, and
Different from the usage of computer resources, the algorithm execution time on the same computer is different.
The time complexity of the algorithm is measured by the number of executions of the basic operations in the algorithm execution process.
The following introduces two concepts: recursion and interfaces.
Recursion means that an algorithm calls itself to complete its work.
This concept is very important both in algorithm and in code writing. When you often go to an interview, there will be an exam like this.
In Shenzhen, companies I have previously interviewed generally have a rabbit series. In my opinion
Use recursive algorithms.
Example ,...... Evaluate the 20th bits
This is actually a recursive relationship: f (n): = f (n-1) + f (n-1)
An interface is a protocol for interaction between classes.
The following lists common interfaces: IComparable, IEnumerable, IEnumerator, ICollection, IDictionary, and IList.
Insert the corresponding generic interface to the package.
The following is an example of an interface:
Public InterfaceIBook
{
StringShowBook ();
StringGetTitle ();
IntGetPages ();
VoidSetPages (IntPages );
}
Public ClassNewBook: IBook
{
Public StringTitle;
Public IntPages;
Public StringAuthor;
PublicNewBook (StringTitle,StringAuthor,IntPages)
{
This. Title=Title;
This. Author=Author;
This. Pages=Pages;
}
Public StringGetTitle ()
{
ReturnTitle;
}
Public IntGetPages ()
{
ReturnPages;
}
Public VoidSetPages (IntPages)
{
This. Pages=Pages;
}
Public StringShowBook ()
{
ReturnTitle+ "," +Author+ "," +Pages;
}
}
Private VoidButton#click (Object