The computer scientist Niklaus Wirth stated that: Programs = Algorithms + Data
计算机科学家Niklaus Wirth提出这样的公式:程序=算法+数据。
The algorithm is part of the blueprint or plan for the computer program; an algorithm is: "An effective procedure for solving a problem in a finite number of steps."
算法是计算机程序的蓝图或计划的一部分,一个算法就是:“用有限的步骤解决问题的有效的过程。”
It is effective, which means that an answer is found and it finishes, that is it has a finite number of steps. A well-designed algorithm will always provide an answer, and it may not be the answer you want but there will be an answer. It may be that the answer is that there is no answer. A well-designed algorithm is also guaranteed to terminate.
所谓有效,就是说找到广了答案并且停止了,也就是说有有限的步骤。一个设计良好的算法总是能得到答案,也许不是希望的答案但是会有答案。也可能答案本身就是没有答案,一个设计良好的算法应该保证能够终止。
The key features of an algorithm are:
Sequence (also known as Process),Decision (also known as Selection),Repetition (also known as Iteration or Looping)
顺序(或者处理)、判断(或者选择)、循环(或者重复)
In 1964 the mathematicians Corrado Bohm and Guiseppe Jacopini demonstrated that any algorithm can be stated using sequence, decision and repetition. The work of Bohm and Jacopini was of great importance since it eventually led to the disciplines of structured program design that are much used today.
数学家Bohm和Jacopini于1964年证明:任何一个程序均可用“顺序”、“判断”和“循环”来陈述。Bohm和Jacopini的工作非常有意义,因为它最终发展成为当前应用广泛的结构化定理。
Sequence means that each step or process in the algorithm is executed in the specified order. In an algorithm each process must be in the correct place, otherwise the algorithm will most probably fail.
顺序算法就是处理过程的每一步以特定的顺序执行,在这种算法中的每一个过程要处在正确的位置,否则算法可能会失败。
The Decision constructs-If ... then, If ... then ... else ...
判断结构——If...then. If... then...else...
In algorithms the outcome of a decision is either true or false, and there is no in between. The outcome of the decision is based on some condition that can only result in a true or false value.
判断算法的结果或者是真或者是假,不可能有中间值。判断的结果基于某些条件,条件的结果只可能是真值或假值。
The decision takes the form: if proposition then process
判断语句的形式为:if (条件)then (过程)
A proposition in this sense is a statement, which can only be true or false. It is either true that today is Wednesday or false that today is Wednesday. It can't be both true and false. If the proposition is true then the process, which follows the then, is executed.
此形式中的条件是一个状态,只能是真或假,譬如:今天是星期三这个说法或者是真或者是假,不可能又是真又是假。如果条件是真,then后的过程被执行。
The decision can also be stated as:
if proposition
then process1
else process2
This is the if ... then ... else ... form of the decision. This means that if the proposition is true then execute process1 else or otherwise execute process2.
这是if... then ...else...形式的判断语句,表示如果条件的结果为真,则执行过程1,否则执行过程2。
The first form of the decision if proposition then process has a null else, that is, there is no else.
第一种形式的判断语句的else为空,也就是说没有else。
The Repetition constructs-Repeat and While
Repetition takes two forms, the Repeat loop and the While loop.
循环有两种形式,直到型循环和当型循环。
The repeat loop is used to iterate or repeat a process or sequence of processes until some condition becomes true. It has the general form:
直到型循环用重复一些过程直到条件为真,一般形式如下:
The repeat loop does some processing before testing the state of the proposition.
这种循环在测试条件状态之前先执行过程。
The while loop is used to iterate or repeat a process or sequence of processes while some condition becomes true. It has the general form:
当型循环当条件为真时重复一些过程,一般形式如下:
The while loop tests the state of the proposition first.
当型循环先测试条件的状态。
There are four different ways of stating algorithms: Step-Form, Pseudocode, Flowchart, and Nassi-Schneiderman.
有四种表示算法的方法:Step-Form、伪代码、流程图和N-S流程图
The first two are written forms. The written form is just normal language. A problem with human language is that it can seem to be imprecise. In terms of meaning, what I write may not be the same as what you read. Pseudocode is also human language but tends toward more precision by using a limited vocabulary.
前两种方法是书写形式的,是普通语言。人类语言的问题是它可能看起来不精确,也就是说作者所写的和读者读到的可能不—致。伪代码也是人类语言,但通过使用少最的词汇而倾向于更精确。
The last two are graphically-oriented, that is they use symbols and language to represent sequence, decision and repetition.
后面的两种是面向图形的,也就是说它们使用符号和语言来表示顺序、判断和循环。
Flow charts are a graphical method of designing programs and once the rules are learned they are very easy to draw. A well-drawn flow chart is also very easy to read.
流程图是程序设计的图形表示法,只要掌握了规则,就很容易画流程图,画得好的流程图也很容易读。
The major symbols are the DECISION (also known as selection) and the SEQUENCE (or process) symbols. The START and STOP symbols are called the terminals. The SUBPROCESS symbol is a variation on the sequence symbol.
主要的符号是判断(或者选抒)和顺序(处理),开始和结束的符号称为端点符号,子过程的符号是顺序符号的变形。