What is an algorithm?

Source: Internet
Author: User
What is an algorithm?

An algorithm is the specific steps and methods required to complete a task. That is to say, given the initial status or input data, after a limited operation by a computer program, the requested or expected termination status or output data can be obtained.

Algorithms often contain repeated steps and comparison or logical judgment. If an algorithm has a defect or is not suitable for a problem, executing the algorithm will not solve the problem. Different algorithms may use different time, space, or efficiency to accomplish the same task. The advantages and disadvantages of an algorithm can be measured by space complexity and time complexity.

Algorithm history
The Chinese name of "algorithm" comes from the weekly computing classics, while algorithm is from the 9-century Persian mathematician Al-Khwarizmi, this is because byal hovanisong proposed the concept of an algorithm in mathematics. "Algorithms" were originally "algorism", which meant that the algorithm of Arabic numerals evolved into "Algorithm" in the 18th century ". The first algorithm was written by Ada Byron in 1842 to compile a program for the babeiqi analyzer to solve the bernuoli equation. Therefore, Ada Byron was considered the first programmer in the world. Because Charles Babbage failed to complete his babbqi analytics machine, this algorithm could not be executed on the babbqi analytics machine. Because "well-defined procedure" lacks accurate mathematical definitions, mathematicians and logical operators in the 19th and 20th centuries have encountered difficulties in defining algorithms. In the 20th century, the British mathematician Turing proposed the famous Turing topic and proposed a hypothetical abstract model of computer called the Turing machine. The emergence of Turing machines solved the difficult problem of algorithm definition. Turing's idea played an important role in the development of algorithms.

Algorithm features
Input: An algorithm must have zero or multiple input values.
Output: An algorithm should have one or more outputs, which are the results of algorithm calculation.
Certainty: The description of an algorithm must be unambiguous to ensure that the execution result of the algorithm is correct.
Poor: algorithms must be implemented within a limited number of steps. Note: "limited" is different from the "limited" of mathematical concepts. The limitations of astronomical numbers are meaningless to practical problems.
Validity: Also known as feasibility. Yes, the operations described in the algorithm can be achieved through the implementation of basic operations for a limited number of times.

Formal Algorithm
Algorithms are the essence of computer processing information, because computer programs are essentially an algorithm that tells the computer the exact steps to perform a specified task, such as calculating the employee's salary or printing the student's transcript. Generally, when an algorithm processes information, it reads data from the storage address of the input device or data and writes the result to the output device or a storage address for future calls.

Time complexity of the algorithm
The time complexity of an algorithm refers to the time resources that the algorithm consumes. Generally, a computer algorithm is a function f (n) of the problem scale N. Therefore, the time complexity of the algorithm is recorded.
[Attachment = 6004]

Therefore, the larger the problem scale N, the growth rate of Algorithm Execution time is positively related to the growth rate of F (n), which is called asymptotic time complexity ).

Spatial complexity of Algorithms
The space complexity of an algorithm refers to the space resources that the algorithm consumes. The computation and Representation Methods are similar to the time complexity. They are generally expressed by the approximation of the complexity. Compared with time complexity, the analysis of space complexity is much simpler.

Non-deterministic polynomial time (NP)

Algorithm Implementation
Algorithms can be implemented not only by computer programs, but also by artificial neural networks, circuits, or mechanical devices.

Example 1
This is a simple example of an algorithm.

We have a series of random numbers. Our goal is to find the largest number in this series. If you think of every number in the series as the size of a bean, you can call the following algorithm as "beans ":

First, put the first bean in the pocket.
Check the second bean until the last one. If the Bean being checked is bigger than the one in the pocket, pick it up and put it in the pocket, and drop the beans in the original pocket.
The beans in the last pocket are the largest of all beans.
The following is a formal algorithm, represented by pseudo code similar to programming languages.

Given: A series "list" and the length of the series "length (list )"
Largest = list [1]
For counter = 2 to length (list ):
If list [Counter]> largest:
Largest = list [Counter]
Print largest

Symbol description:

= Indicates the value assignment. That is, the value on the right is assigned to the variable on the left.
List [Counter] indicates the counter entry in the series. For example, if the counter value is 5, list [Counter] indicates 5th items in the series.
<= Indicates "less than or equal ".

Example 2
Calculate the maximum common divisor of two natural numbers. set two variables M and N.

If M <n, m and n are exchanged.
M is divided by N to obtain the remainder R.
If r = 0 is determined, the value n is the "maximum common number". Otherwise, the next step
Assign n to M, assign R to N, and redo the first step.
Use "Basic code" to represent --

If M <n then swap m, n
Do While r <> 0
R = m mod n
M = N
N = r
Loop
Print n

Basic algorithm design and analysis methods
Divide and conquer Law
Dynamic Planning
Greedy method (also called greedy method)

Classification of Algorithms
Basic Algorithms
Enumeration
Search
Deep Priority Search
Extended search
Heuristic Search
Genetic Algorithm
Data Structure Algorithm
Number Theory and algebra algorithms
Geometric calculation algorithm
Convex hull algorithm
Graph Theory Algorithms
User ID
Tree traversal
Shortest Path Algorithm
Minimum Spanning Tree Algorithm
Minimum Tree Structure
Network Flow Algorithm
Matching Algorithm
Dynamic Planning
Others
Numerical Analysis
Encryption Algorithm
Sorting Algorithm
Search Algorithm
Randomization algorithm
Parallel Algorithms

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.