# Pseudo Code)

Source: Internet
Author: User
Original pseudocode: pseudo code by Naomi Nishimura
Translated by Liu Jianwen (http://blog.csdn.net/keminlau)

In the text and lectures, algorithms will often be expressed in pseudo docode, a mixture of code and English (for speci should C not necessarily good examples of particle pseudo docodes, see p. 17 of the course text, or the examples in the books the design and analysis of computer algorithms
By Aho, hopcroft, and Ullman, Addison-Wesley, 1974, computer algorithms: Introduction to design and analysis by baase, 1978, and fundamentals of computer algorithms by Horowitz and Sahni, computer Science Press, 1984 ). while understanding pseudo docode is usually not
Difficult, writing it can be a challenge.

Pseudocode is a mixture of English and Code. It is not difficult to understand pseudocode, but writing pseudocode is very challenging.

Why use pseudo code at all? Pseudo Code strikes a sometimes precarious balance between the understandability and informality of English and the precision of code. if we write an algorithm in English, the description may be at so high a level that it is Di has cult to analyze the algorithm
And to transform it into code.

If instead we write the algorithm in code, we have invested a lot of time in determining the details of an algorithm we may not choose to implement (as we typically wish to analyze algorithms before deciding which one to implement ). the goal of writing pseudo docode, then, is to provide a high-level description of an algorithm which facilitates analysis and eventual coding (shocould it be deemed to be "Good" Algorithm) but at the same time suppresses detail of the details that vanish with asymptotic notation. Finding the right level in the tradeo between readability and precision can be tricky ......

Why do we need to use pseudocode? (Because) pseudocode balances the Ambiguity Caused by comprehension and non-forms of English (Natural Language) and the contradiction between the accuracy of code. If we use English (Natural Language) to write algorithms, the algorithm description may be too high-level and difficult to analyze the algorithms and convert them into actual code. If we use code to write algorithms, we have to spend a lot of time on some code details that we may not ultimately implement (because we generally analyze the algorithm logic before implementing the algorithm ). The objective of writing pseudo code (to describe the algorithm with an appropriate expression) is to facilitate algorithm analysis and ultimately implement encoding, but at the same time restrain asymptotic notation) A large number of details are erased. Finding an appropriate balance between readability and accuracy is quite difficult (tricky: the problem is hard to handle and requires a lot of effort ......

Just as a proof is written with a type of reader in mind (hence proofs in undergraduate textbooks tend to have more details than those in Journal Papers ), algorithms written for different audiences may be written at di specified erent levels of detail. in assignments and exams for the course, you need to demonstrate your knowledge without obscuring to blur the big picture with unneeded detail. here are a few general guidelines for checking your pseudo code:

Just like a (mathematical) proof that there are pre-defined reader types, different readers may have different levels of programming details. The following are the reference principles for writing pseudocode:
1. mimic imitates good code and good English. using aspects of both systems means adhering to the style rules of both to some degree. it is still important that variable names be mnemonic, comments be encoded where useful, and English phrases be comprehensible (full sentences are usually not necessary ).

It is similar to the code or English (expression ). It means to absorb the advantages of both in expression to some extent. For example, use a variable name that is easy to remember, use comments appropriately, and use a well-understood English phrase.
2. ignore unnecessary details. if you are worrying about the placement of commas, you are using too much detail. it is a good idea to use some convention to group statements (begin/end, brackets, or whatever else is clear), but you shouldn't obsess about syntax.

Ignore unnecessary details. If you frequently use commas (,), it means that you write them too carefully. It is a good idea to use begin/end or parentheses to combine multiple statements, but it cannot be distracted by syntax.
3. don't belabur no need to explain the obvious. in our cases, the type of a variable is clear from context; unless it is critical that it is speci already ed to be an integer or real, it is often unnecessary to make it explicit.

Do not explain what is obvious. In many cases, the type of a variable is obvious in the context, unless its specific type (such as integer or real number) is crucial, it is not necessary to explicitly describe its type.

4. take advantage of programming shorthands. using if-then-else or looping structures is more concise than writing out the equivalent in English; General constructs that are not peculiar to a small number of classes are good candidates for use in pseudo docode. using parameters in specifying procedures is concise, clear, and accurate, and hence shoshould not be omitted from pseudo code.

Use the shorthands programming tool. The use of the if-then-else or loop structure is more concise than the expression in English; some general language structures can also be used in pseudocode (fixme ). Specifying parameters for a function is concise, clear, and accurate and should not be removed from pseudo-code.

5. consider the context. if you are writing an algorithm for quicksort, the statement "use quicksort to sort the values" is hiding too much detail; if we have already studied quicksort in class and later use it as a subroutine in another algorithm, the statement wocould be appropriate to use.

Consider the context. If you write an algorithm for a quick sort, the statement "use quicksort to sort the value" hides too many details. If you have learned the Quick Sort Algorithm, now we can use this statement to describe it as a sub-process of another algorithm.

6. don't lose sight of the underlying model. it shoshould be possible to "see through" Your pseudo docode to the model below; if not (that is, you are not able to analyze the algorithm easily ), it is written at too high a level.

Do not confuse the models under the algorithm. It is possible to see through the model under your pseudo code. If not, it proves that the writing is too high (not detailed enough), so it is difficult for you to analyze algorithms.

7. Check for balance. If the pseudo code is hard for a person to read or di receive cult to translate into working code (or worse yet, both !), Then something is wrong with the level of detail you have chosen to use.

Check (readability and accuracy) balance. If the pseudocode is hard to understand or translate into the source code, the details of your pseudocode must be somewhere wrong.

(Author: Naomi Nishimura)

Kemin said:
B. Mentally retarded people play IDE, smart people play programming languages, and smart people play pseudocode. Of course, there is a higher level. Do you want to know? Ask God.
Kemin said:
B. it seems that pseudo-code is a little more natural language, or a little more source code, it is not necessary to be too accurate, too limited, because as long as the code reader can take some time to enter the status, in the context of the problem, even the source code that is "annoying" and magic can be understood. Otherwise, the natural language and some people can't understand the explanation. Therefore, the Abstraction Level of pseudo-code does not remain unchanged and varies from person to person.

Reference
• Http://en.wikipedia.org/wiki/Pseudocode
• Http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/
• Use of pseudocode http://www.comp.nus.edu.sg /~ Xujia/mirror/algorithm.myrice.com/algorithm/pseudo docode.htm
• Pseudo Code Standard http://users.csc.calpoly.edu /~ Jdalbey/SWE/pdl_std.html
• 'Pseudo-code conventions 'http://bigwhite.blogbus.com/logs/2443206.html in Algorithm Description
Related Keywords:

### 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.