Concept of algorithms and use of pseudocode

Source: Internet
Author: User

Algorithm

An algorithm is a set of clearly defined rules used to solve a problem within a limited step. In layman's terms, it is the process of solving computer problems. In this process, whether it is to form a problem-solving idea or programming, it is to implement a certain algorithm. The former is an algorithm implemented by reasoning, and the latter is an algorithm implemented by operations. An algorithm should have the following five important features: poorer: An algorithm must end after a finite step is executed; definite: each step of the algorithm must have a definite definition; input: an algorithm has 0 or more inputs to characterize the initial state of an operation object. The so-called 0 inputs indicate that the algorithm determines the initial condition, and the output: an algorithm has one or more outputs to reflect the results of input data processing. An Algorithm Without output is meaningless. Feasibility: in principle, the algorithm can be accurately run and can be completed only after a limited number of computations are performed by pen and paper.
The origin of did you knowalgorithm is very interesting. At first glance, it seems that someone is planning to write the word "logarithm" (logarithm), but the four letters are reversed. This word was not found in Webster's New World Dictionary (the New World Dictionary of Wei's) until 1957, we can only find the old form of "algorism" (arithmetic) with its ancient meaning, which refers to the process of arithmetic operations using Arabic numerals. In the Middle Ages, abacus was used for calculation, while arithmetic was used for calculation. After the Middle Ages, the term's origins were no longer certain, and the early linguistics tried to deduce its origins, believing it was from putting algiros (laborious) + arithmos (numbers) it is derived from the combination, but others disagree with this statement and believe that the term is derived from "King algor of casyr. Finally, the mathematical historian discovered the true origins of the word algorism (arithmetic): it came from the famous Persian textbook (Persian textbooks). the author's name is Abu Ja 'far Mohammed Ibn M û s â al-khowâ rizm (around 825 BC)-literally, this name means "Ja 'far's father, Hammed and M ~sâ's son, howâ rizm's local ". Howâ rizm is a small town in the former Soviet Union of X Pacific Ba (Kifa. Al-khowâ rizm wrote the famous book Kitab Al Jabr w'al-muqabala ("restoration and simplification Rules"); another word, "Algebra" (algebra ), it is derived from the title of his book, although this book is not actually about algebra. Gradually, the form and meaning of "algorism" become completely beyond the view. As explained in the Oxford English Dictionary, this word is a misspelled word due to confusion with arithmetic (arithmetic. From algorism to algorithm. An early German mathematical dictionary vollstandiges mathematisches Lexicon () provides the following definition of the word algorithmus (algorithm): "under this name, it combines four types of arithmetic computing concepts: addition, multiplication, subtraction, and division ". The randing phrase algorithmus infinitesimhei (infinitely small method) was used to represent the calculus method invented by Leibnitz (Leibnitz) for computation in an infinitely small amount. Around 1950, the term algorithm was often associated with the Euclidean Algorithm (Euclid's algorithm. This algorithm is based on Euclidean's ry (Euclid's elements, Volume VII, proposition I and II) the process of finding the maximum common divisor of two numbers (I .e. the moving phase division) described in ). Abu Ja 'far Hammed Ibn M û s â al-Khow â rizm born: About 780 in Baghdad (now in Iraq) died: about 850. The use of pseudo-code usage of pseudo-code is an algorithm description language. The purpose of code is to make the described algorithm easy to implement in any programming language (Pascal, C, Java, etc. Therefore, pseudo-code must have a clear structure, simple code, good readability, and similar to natural languages. The following describes the syntax rules for pseudo-code in Pascal. The syntax rules of pseudo-code are in pseudo-code. Each Command occupies one line (except else if,), and the command is not followed by any symbols (the statements in Pascal and C should end with a semicolon ); the "indent" in writing indicates the branch program structure in the program. This indent style also applies to if-then-else statements. Replacing the begin and end statements in traditional Pascal with indentation to represent the block structure of the program can greatly improve the clarity of the Code. The statements in the same module have the same indentation, the statements of the level-1 module are indented to those of its parent module. For example: line 1 line 2 sub line 1 sub line 2 sub line 1 sub line 2 sub line 3 in Pascal, this relationship is expressed by nesting of begin and end, line 1 line 2 begin sub line 1 sub line 2 begin sub line 1 sub line 2 end; sub line 3 end; line 3 is represented by the nesting of {And} in C. Line 1 line 2 {sub line 1 sub line 2 {sub line 1 sub Line 2} Sub line 3} line 3 in pseudocode, consecutive numbers or letters are usually used to mark the continuous statements in the same module. Sometimes, labels can be omitted. Example: 1. line 1 2. line 2. sub line 1 B. sub line 2 1. sub line 1 2. sub line 2 C. sub line 3 3. the content after the △ symbol of Line 3 represents comments. In pseudo-code, variable names and reserved words are case-insensitive, which is the same as Pascal and different from C or C ++. In pseudo-code, the variable does not need to be declared, but the variable is partial to a specific process. The global variable is used without the display instructions. The value assignment statement is represented by the symbol 'struct', And the 'X' exp indicates that the exp value is assigned to X, X is a variable, and exp is a variable or expression of the same type as X (the result of this expression is the same as X ); the multiple assignment I between j between E is to assign the value of expression E to the variables I and J, which is equivalent to j between E and I between E. For example, the statements of X ← Y x ← 20 * (Y + 1) x ← y ← 30 and above are represented as follows in Pascal: X: = y; X: = 20 * (Y + 1); X: = 30; Y: = 30; the preceding statements are represented as: x = y in C; X = 20 * (Y + 1); X = y = 30; the SELECT statement is represented by if-then-Else, and such if-then-else can be nested, it is no different from if-then-else in Pascal. For example, if (condition1) then [block 1] else if (condition2) then [block 2] else [block 3] loop statements have three types: the syntax of the while loop, repeat-until loop, and for loop is similar to Pascal, but the in-end is replaced by indentation. For example: 1. X defaults 0 2. Y limit 0 3. Z limit 0 4. while x <n 1. do x merge x + 1 2. Y then X + Y 3. for T defaults 0 to 10

1. do z Merge (z + x * y)/100 2. repeat 1. y ← y + 1 2. z-y 3. until z <0 4. z limit x * y 5. y ← y/2 The preceding statement is described in Pascal as follows: x: = 0; y: = 0; z: = 0; while x <N do begin x: = x + 1; y: = x + y; for t: = 0 to 10 do begin z: = (z + x * y)/100; repeat y: = y + 1; z: = z-y; until z <0; end; z: = x * y; end; y: = y/2; the preceding statement uses C or C ++ to describe x = y = z = 0; while (z <N) {x ++; y + = x; for (t = 0; t <10; t ++) {z = (z + x * y)/100; do {y ++; z-= y ;}while (z> = 0 );} z = x * y;} y/= 2; array elements are stored in the array name and are indicated by "[subscript. For example, A [j] indicates the j-th element of array. Symbol "…" Used to indicate the range of values in the array. Example: A [1... J] indicates the elements A [1], A [2],…, A [j] sub-array. The composite data is represented by an Object. The Object consists of attribute and field. Domain access is represented by the object name enclosed by square brackets after the domain name. For example, an array can be considered as an object. Its attribute has length, which indicates the number of elements. length [A] indicates the number of elements in array. Square brackets are used to represent the array elements and Object Attributes. The meaning of square brackets can be seen from the context. Variables used to represent an array or an object are treated as pointers to data that represents an array or an object. If f is assigned to all the fields of an object x, f [y] = f [x] is used to make f [x]. If f [x] Isn 3, then not only f [x] = 3, but also f [y] = 3. In other words, after the value of y ← x, x and y point to the same object. Sometimes, if a pointer does not point to any object, we assign it nil. The syntax of functions and procedures is similar to Pascal. Function values are returned using the "return (function return value)" statement. The Calling method is similar to Pascal. The call process name is used to call a function value. For example: 1. x Tb t + 10 2. y ← sin (x) 3. the call CalValue (x, y) parameter is passed to a process by value: a copy of the accepted parameter in the called process. If a parameter is assigned a value, this change is invisible to the calling process. When an object is passed, only the pointer pointing to the object is copied without copying its fields.

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.