Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Algorithms, Flowcharts and Pseudocodes 1. Overview The term "algorithm" is used for describing the sequence of actions leading to the solution of the given problem. The field of mathematics known as the theory of algorithms is dedicated to the study of the properties, methods of recording, the creation of new algorithms and the application of different algorithms. Basic requirements to the algorithms used in computer science are the following: Discreteness: the algorithm should lead to the solution of the assigned problem, introducing the solution of the problem as a sequence of actions. Finiteness: the number of steps of the algorithm must be finite. Efficiency: the algorithm must be such that a solution could be found in a finite and reasonable time. Certainty (or precision, determinacy): algorithm's steps have to allow unambiguous interpretation. Each algorithm has to be devised for a certain performer. In order that the performer could solve the problem according to the given algorithm, it is necessary that it would be able to understand and perform each action instructed by the algorithm. Any action of the algorithm must be strictly defined and described in each case. Effectiveness: the algorithm must produce concrete results. Moreover, the message that the problem has no solution means the result. Versatility: the algorithm must be developed so that it could be used to solve similar problems (For example, the rules of addition and multiplication of numbers are suitable for any numbers and not for any specific ones.). One can outline the ways of describing of algorithms as follows: Verbal: the description of an algorithm is performed in an ordinary language. The disadvantage of this method is the fact that such descriptions are not strictly formalized and wordy. This way can contain ambiguities. Graphical: this method is more intuitive and compact compared to the verbal description. Formal algorithmic languages (programming languages): this way uses strict rules of construction of language constructs. Pseudocode: synergy of algorithmic and ordinary languages. Pseudocode can be based on national languages (English, Estonian, Russian etc.). Uses English (Estonian, Russian etc.)-like phrases to outline the task. Now we consider one of the forms of a graphical representation of an algorithm called flowchart as well as the corresponding pseudocode. 2. Flowcharts and pseudocode There are two commonly used tools to help to document program logic (the algorithm). These are flowcharts and pseudocode. Generally, flowcharts work well for small problems but pseudocode is used for larger problems. We will use both methods here. Flowchart is a graphical representation of an algorithm as series of interrelated functional blocks, each of which corresponds to the implementation one or more actions. In a flowchart each type of actions (data input, evaluating expressions, checking the conditions, management of the repetition of actions, end processing, etc.) corresponds to the geometric shape, presented in the form of block symbol. Inside the block the description of the appropriate action is given. The blocks are connected by lines of transitions that determine the order of implementation of the actions. General rules for flowcharts: All symbols of the flowchart are connected by flowlines (note arrows). Flowlines enter the top of the symbol and exit out the bottom, except for the Decision symbol, which can have flowlines exiting from the bottom or the sides. Flowcharts are drawn so flow generally goes from top to bottom. The beginning and the end of the flowchart is indicated using the Terminal symbol. Algorithms can be represented as some structures consisting of individual basic elements. Naturally, according to such an approach to algorithms the study of basic principles of their construction must begin with the study of these basic elements. The logical structure of an algorithm can be represented by combination of three basic structures: Following, Branching, Loop. 1. Basic structure "following" is a linear algorithm. It is formed of a series of actions that follows one after the other: Flowchart: Pseudocode: Activity 1 Activity 2 Activity 3 Verbal description: Each activity is performed one after another in sequence order. Example: Draw a flowchart for this function: y = x2 + 4x + 3. You can use only the operations of addition and multiplication. You can see that it is not a precise definition of the task. It is not defined how we must compute the function. Hence, we assume in this case that it is possible to calculate the value of the function at once. Therefore, we can depict the following flowchart: 2. The basic structure of "branching" is a branching algorithm. Depending on the result of the check of a condition («Yes» or «No»), it provides the choice one of the alternative paths of the algorithm. Each of the pathways leads to a common output, so that the algorithm will continue regardless of which path is chosen. In the following, we assume the structure "branching" exists in four basic versions: IF-THEN (incomplete branching) IF-THEN-ELSE (full branching) SELECT (incomplete) SELECT-ELSE (full) 1) IF-THEN Pseudocode: IF Decision THEN Activity 1 END-IF Verbal description: If the Decision is true ("Yes"), the following actions(Activity 1) are performed, otherwise the transition to the next step is made at once, if any. The corresponding snippet of a flowchart is: 2) IF-THEN-ELSE Pseudocode: IF Decision THEN Activity 1 ELSE Activity 2 END-IF Verbal description: If the Decision is true ("Yes"), the following actions (Activity 1) are performed, else ("No") the Activity 2 is performed. The corresponding snippet of a flowchart is: 3) SELECT Pseudocode: SELECT CASE Decision 1: Activity 1 END-CASE CASE Decision 2: Activity 2 END-CASE CASE Decision 3: Activity 3 END-CASE ... END-SELECT Verbal description: If the Decision 1 is true, then the Activity 1 actions are performed, if the Decision 2 is true, then the Activity 2 actions are performed, if the Decision 3 is true, then the Activity 3 actions are performed, ... The corresponding snippet of a flowchart is: 4) SELECT-ELSE Pseudocode: SELECT CASE Decision 1: Activity 1 END-CASE CASE Decision 2: Activity 2 END-CASE CASE Decision 3: Activity 3 END-CASE ... ELSE Activity 4 END-SELECT A verbal description is: If the Decision if the Decision if the Decision ... else Activity 4 1 is true, then the Activity 1 actions are performed, 2 is true, then the Activity 2 actions are performed, 3 is true, then the Activity 3 actions are performed, actions are performed. The corresponding snippet of a flowchart is: