Algorithmic languages ​​and programming. Algorithms. Algorithmization. Algorithmic language Basic mathematical functions in algorithmic language

Any programming language is replete with a variety of keywords, functions or classes. As a rule, they all use English, which describes methods or arguments. In some environments, there are simply abbreviations of machine functions. This greatly hampered the development of development at the initial stages. In order to increase the speed of understanding, a series of special algorithmic programming languages ​​were created, which consisted of understandable and accessible words and their combinations, clear even to an untrained person.

A little history

To communicate with the first computers, programming languages ​​were used that were as close as possible to machine code, consisting of zeros and ones. Naturally, remembering a lot of commands was a very difficult task. In addition, the method of memory allocation during programming rested entirely on the shoulders of the developer. And if he made a small mistake, he had to redo everything all over again.

A large role in the transition from machine language to a more suitable language for humans was played by the low-level programming language assembler. It used mnemonics and symbols. This simplified the developer’s task, since now he could more productively build his algorithms from combinations of control instructions and numeric codes. Despite all its flexibility and power, the language was still difficult to master.

To teach development and algorithms in educational institutions, the introduction of the BASIC programming language began. It already contained many commands and keywords that were understandable to the learner. BASIC is still used to learn the basics of programming.

With the creation of the first algorithmic programming language, Algol, the development of algorithms accelerated significantly.

What is the algorithm

If we move away from dry theory and definitions, then an algorithm is a sequence of actions aimed at solving a given problem. Despite all the floridness of the expression, a person encounters this concept every day. For example, to drink tea, you need to follow the following sequence:

  1. Place the kettle on the stove.
  2. Wait for it to boil.
  3. Pour boiling water into the water.
  4. Place the tea bag into the cup.
  5. Add the required amount of sugar, milk or honey.

This sequence is very simplified, but it represents the simplest algorithm.

Just like a person, a computer is capable of performing a certain sequence of tasks. However, in order for it to clearly understand them, it must be taken into account that a computer lacks many concepts that are obvious to people. In addition, the algorithm must accurately describe all necessary actions. An algorithmic language serves this purpose, creating a kind of bridge between machine and human.

Properties and features of an algorithmic language

Algorithmic is a formal language in which algorithms intended to be executed on computers are described. Typically, it is not tied to any machine architecture. This helps significantly improve and speed up coding. A striking example is the algorithmic language BASIC. Pascal and C also proved popular due to their simple syntax and speed of learning.

The structure is implemented in such a way that the procedures described in the code are executed one after another. That is, one algorithm - one task. This is similar to creating functions or methods in C and Java.

All code is built from keywords that describe an event or variable.

Differences between machine and algorithmic languages

A striking representative of a machine-dependent language is assembler. Programming on it comes down to indicating to the translator with special marks what needs to be moved and where or what data area to fill. Since the assembler syntax is more similar to machine syntax, it is quite difficult to study and write code in it. Below you can see what the commands might look like for different processors.

Therefore, a formal or algorithmic language was created with a large number of human-understandable keywords and names.

Keywords

Algorithmic language consists of keywords, which are abbreviations for the complete designation of actions or variables. This allows you to reduce the length of the code while keeping it understandable.

  • Alg. Any algorithm begins with this keyword. It describes the name and states in parentheses what arguments it takes for the calculation and what the result should be.
  • Arg. Denotes the arguments of the algorithm. Reflects the type and name of the value that will be used in the code.
  • Res. This keyword serves to indicate the type and name of the variable in which the result of the calculation will need to be placed.
  • Beginning Indicates the immediate start of the algorithm execution. Lasts until the con keyword. The entire interval from “start” to “end” is called the body of the current algorithm.
  • Con. Indicates that the algorithm has completed execution.
  • Given. Talks about some of the features and nuances of using the algorithm or limitations. For example, here you can specify that the lengths of the compared strings must be the same. The use of the keyword "given" is optional.
  • Necessary. A more detailed description of what should be obtained as a result of executing the algorithm. Just like “given,” it can be omitted, but to build more understandable and detailed code, its use is recommended.

The list of these keywords refers to the title and body designation of the algorithm. And this is what tokens for variables look like:

  • Cel. Integer variable type. Their range should vary from -32768 to 32767.
  • Thing. Real numbers. For example, with an exponent or fractional part.
  • Log. This keyword means that a Boolean variable will be used that can only accept "yes" or "no".
  • Sim. This includes values ​​with single characters, such as "a", "3".
  • Lit. String variables that can contain entire text strings.
  • Tab. Designates a table with data of a certain type. It is an analogue of an array from other programming languages.

Additional function words

The following list of words is used to organize branching and looping mechanisms.

  • For. Used to iterate through all values ​​of a certain range. Used for cycles, i.e., continuous execution of any procedures with data.
  • From and to. Indicates which specific range of values ​​should be iterated through in a "for" loop.
  • Bye. Also used to iterate over multiple values. Used to work until a certain condition is met.
  • Nts and kts. “Nts” in algorithmic language means the beginning of the loop body, and “kts” means the end. Between these two keywords the procedures necessary for the calculation are built in.
  • If. This word implements the branching structure. In this way, it is possible to determine the progress of the program in the desired direction, taking into account the conditions.
  • Either way. Two words that work with "if". The branching mechanism is also built.
  • Choice. A convenient tool for branching from several values ​​of the same type. Works in conjunction with the keyword "at" and "otherwise".
  • All. Indicates the end of the branching mechanism.
  • Enter. This keyword allows the user to enter variable values ​​during program operation for subsequent processing.
  • Conclusion. Displays data on the screen.

Basic language structures

An algorithmic programming language helps to build various structures that produce computational functions in a convenient form. In general, any language can use several specific mechanisms and their combinations.

Following structure

When designing this type of structure, code execution occurs directly line by line. A general example can be expressed this way:

alg Sum of two numbers (arg int a, b, res int S)

output "S = ", S

In this example, the sum of two numbers entered by the user is calculated. At the beginning, the word "alg" indicates that the algorithm is starting and briefly describes what exactly it does. The arguments needed for the program to run and the variable that will serve as a container for storing the results are defined in parentheses. Next comes the keyword “start”, indicating the immediate start of execution of expressions and procedures. Next to "start" you can also define some intermediate variables.

In the body of the algorithm, the "input" keyword accepts data from the user and writes it to variables. They are then added together and their sum is assigned to S. Before the end of the algorithm, the result of the program is displayed on the screen using the keyword "output". This notation in algorithmic language is typical for many other programming environments.

Branching structure

The flow of a program does not always have to be executed line by line. Sometimes you need to determine or change the value of a certain variable depending on the situation. For example, given that x = 0, do not divide by x.

An algorithmic programming language does this by using several variant constructs and the keywords “if,” “then,” “else,” or “choice.” After “if” a condition is set by which the criterion for moving to another branch will be determined. For example, like this:

This way you can change the values ​​of variables depending on other factors. This example does not fully cover all possible implementations. Therefore, in addition to the construction, the keyword “otherwise” is applied. It allows you to move to another branch if the condition does not meet the selected criteria.

otherwise y = 0

That is, in the case when x is not equal to zero, y will also be reset to zero, regardless of the value it had before.

A more convenient means of making multiple choices is the “choice” construct. It allows you to sort through several conditions. When one of them is triggered, the action specified for it will be performed.

at x = 0: y = 0

at x = 1: y = 1

at x = 2: y = 2

This example demonstrates the dependence of the variable y on x. The program runs through all the data and compares the current value of x with the one specified in the condition. When a match is found, it performs the next action. This construction can also be combined with the keyword "else" for more flexible solutions when none of the conditions are met.

Cycles

Loops play a very important role in programming. Almost no development can do without the implementation of this design. In general, loops solve the problem of performing similar actions with several variables repeatedly. This is convenient, for example, when filling arrays with data using a known formula, sorting it, or counting some values.

The keyword "while" allows you to organize a loop in which a certain action will be repeated until a certain condition is satisfied. For example:

nts bye x<= 3

In this example, y will increase until x becomes greater than 3. In order for the loop not to be endless, x needs to be changed upward in each pass, for example by 1, which is what the second line of code does.

The keyword "for" is applied to a certain range of numbers that needs to be iterated through sequentially, performing some actions with them. This construction is used when a finite number of elements is known.

Its syntax looks like this:

nc for x from 1 to 3

The service words "from" and "to" show the range of values ​​that need to be iterated. Thus, in the first iteration x = 1, as a result of the pass, y will also acquire the value 1. Then control will again go to the beginning, and x will now be equal to 2, respectively, y will become 3.

Using the combined constructions of loops and branching, you can build the simplest algorithms for solving easy problems and gaining knowledge about the operation of programming languages.

Standard Features

An algorithmic language has standard functions that are already built into it. They can make some routine operations with numbers and expressions easier. Standard functions of the algorithmic language can calculate square roots, logarithms, modules, sines, cosines, etc.:

  • absolute module - abs(x);
  • square root - sqrt(x);
  • natural and decimal logarithms - ln(x) and log(x);
  • minimum and maximum of two numbers - min(x,y), max (x,y);
  • sine, cosine, tangent, cotangent - sin(x), cos(x), tan(x), ctg(x).

These standard features allow you to avoid creating a “bicycle” by helping to implement the simplest functions using standard tools.

Boolean expressions

Boolean expressions reflect whether a certain operation satisfies a condition. For example, x > 0 will evaluate to true when x is 1, 2, 25, or any other number greater than zero. The algorithmic language contains logical expressions that, in addition to standard mathematical operations, can use the following keywords and operators:

  • AND. Means that the expressions between which the keyword is located must satisfy a certain condition: (x>0) and (y>0);
  • Or. One of the expressions may not satisfy the condition, for example, (x>0) or (y>0);
  • Not. "Flips" the logical value of an expression. For example, this design Not(x>0), means that x must still be no more than zero.

There are also comparison operators -<, >, =, which can be combined to create expressions like greater than or equal to.

A small program for an algorithmic language

To understand the process, you can organize a program that interacts with the user. It will ask for a number, and the machine will square it.

The components of an algorithmic language contain many keywords. The first thing the program begins with is an announcement about the algorithm - alg.

alg Square a number ()

In parentheses you need to specify an argument that will represent the value from the user and the result. Also, do not forget about declaring the types of this data.

Now the machine will know that it will have to interact with a variable of type integer, and the result of its work will be S.

The first thing you need to do is enter data. This is done using the "input" keyword.

Now, directly in the body of the algorithm, you need to describe a number of commands that will be used to calculate the squares of numbers.

output "S = ", S

An algorithmic language, the commands of which allow the assignment to be implemented, are written in the form: =. Thus, the variable S contains the value of the product of x and itself. The output line shows the result on the screen. Well, all this ends with the keyword “con”. The complete code will now look like this:

alg Square a number (arg integer x, res integer S)

output "S = ", S

This is how the algorithm for calculating the square of the entered number is implemented in a simple way. The program can be complicated by adding to it the sum of all operations. And then it will look like this:

alg Square a number and calculate their sum (arg integer x, res integer S)

given | x > 0

need | S = 1*1 + 2*2+ … + x*x

start whole

input x; S:=0

nc for a from 1 to x

output "S = ", S

This option uses a loop, an intermediate variable a, and a brief indication of the task in the “given” and “must” sections. Now, if you pass a certain number to the program, it will square it and display the sum of the squares of all the numbers preceding it.

Use and development of algorithmic languages

Algorithmic language is common in learning environments for understanding the basic norms and rules of programming. For example, BASIC, which is taught in many schools. It perfectly reflects all the paradigms of such a term as an imperative programming language, in which all commands are executed sequentially one after another.

Due to the proximity of the described constructs and keywords to the human language, writing code has become much easier than using completely machine or machine-dependent models. The ALGOL family of programming languages ​​has gone the furthest in its development, since its syntax was presented in several localizations. It was possible to write code even in Russian.

In general, the development of algorithmic languages ​​has greatly influenced programming in general and allowed a large number of people to become developers. Modern means are becoming more accessible and understandable. High-level programming languages ​​contain more and more functions with meaningful names and titles. The limits to their use are becoming ever smaller. Thus, a more understandable and natural implementation of the development is possible in the future.

Recording an algorithm in an algorithmic (formal) language is called a program. Sometimes the very concept of an algorithm is identified with its notation, so that the words “algorithm” and “program” are almost synonymous. A small difference is that when mentioning an algorithm, they usually mean the basic idea of ​​its construction, which is common to all algorithmic languages. The program is always associated with writing the algorithm in a specific formal language.

When presenting the idea of ​​an algorithm, for example, when publishing it in a scientific article, it is not always advisable to use any specific programming language, so as not to clutter the presentation with unimportant details. In such cases informal algorithmic language is used, as close to natural as possible. This type of language is called pseudocode. It is not difficult for a specialist to rewrite a program from pseudocode into any specific programming language. Writing an algorithm in pseudocode is often clearer and more visual; it allows you to freely choose the level of detail, from a description in very general terms to a detailed presentation.

Pseudocodes are semi-formalized descriptions of algorithms based on conditional algorithmic language, including both elements of a programming language and natural language phrases, generally accepted mathematical notations, and more.

Pseudocode is a system of notations and rules designed to uniformly write algorithms.

Pseudocode occupies an intermediate place between natural language and programming languages. On the one hand, it is close to ordinary, natural language, so algorithms can be written and read in it like regular text. On the other hand, pseudocode uses some formal constructs and mathematical symbolism, which brings the algorithm notation closer to the generally accepted mathematical notation.

Pseudocode usually contains some constructs that are native to programming languages. This facilitates the transition from writing in pseudocode to writing the algorithm in a programming language for a specific computer. In particular, in pseudocode, as well as in programming languages, there are function words, the meaning of which is determined once and for all. They appear in bold in printed text and are underlined in handwritten text.

General view of the algorithm:

alg name of the algorithm (arguments and results)

given conditions for applicability of the algorithm

necessary purpose of the algorithm

beginning description of intermediate quantities

sequence of commands(algorithm body)

Part of the algorithm from the word alg to the word beginning is called the heading, and the part between the words beginning And con - body of the algorithm.

In a sentence alg after the name of the algorithm, the characteristics (arg, res) and value type (integer, thing, sim, lit or log) of all input (arguments) and output (results) variables are indicated in parentheses. When describing arrays (tables), a special word is used tab, supplemented by boundary pairs at each array element index.

Example sentences alg :

alg Volume and area of ​​the cylinder (arg things R, H, res things V, S)

alg Roots KvUr ( arg thing a, b, c, res things x1, x2, res lit t)

alg Exclude element ( arg integer N, arg res things tab A)

alg Diagonal ( arg integer N, arg whole tab A, res lit Answer)

Offers given And necessary not required. It is recommended to write down statements describing the state of the environment of the algorithm executor, for example:

alg Replacement (arg lit Str1, Str2, arg res lit Text)

given | the lengths of the substrings Str1 and Str2 are the same

need | Everywhere in the Text line, the substring Str1 is replaced by Str2

alg Number of maxima (arg int N, arg thing tab A, res int K)

given | N>0

need | K - the number of maximum elements in table A

alg Resistance (args things R1, R2, args int N, res things R)

given | N>5, R1>0, R2>0

need | R - circuit resistance

Here in sentences given And necessary after the "|" sign comments recorded. Comments can be placed at the end of any line. They are not processed by the translator, but make the algorithm much easier to understand.

Basic function words of the algorithmic language:

alg (algorithm) sim (symbolic) given for yes

arg (argument) lit (literal) necessary from no

rez (result) log (logical) if before when

beginning (beginning) tab (table) then value selection

end (end) nc (start of cycle) otherwise and input

int (integer) kts (end of loop) all or output

thing (real) length (length) not yet approved

Basic commands:

1. Assignment command. Used to evaluate expressions and assign their values ​​to variables. General form: A:= B, where is the sign ":=" means a command to replace the previous value of the variable on the left side with the calculated value of the expression on the right side.

For example: a:= (b+c) * sin(Pi/4); i:= i+1.

Input and output commands.

input variable names (keyboard input)

conclusion variable names, expressions, texts. (display data on screen)

Branching commands.

These commands provide, depending on the result of checking the condition (yes or no), the choice of one of the alternative ways of operating the algorithm. Each path leads to a common output, so the algorithm will continue to run no matter which path is chosen.

The branching structure comes in four main variations:

1. Team if - then;

If condition

That actions

2. Team if - then - otherwise;

If condition

That actions 1

otherwise actions 2

3. Team choice;

Choice

at condition 1: actions 1

at condition 2: actions 2

. . . . . . . . . . . .

at condition N: actions N

4. Team choice is different.

Choice

at condition 1: actions 1

at condition 2: actions 2

. . . . . . . . . . . .

at condition N: actions N

otherwise actions N+1

Cycle commands.

Provides repeated execution of a certain set of actions, which is called the body of the loop.

There are two commands for organizing loops:

1. Loop type Bye - Orders the body of the loop to be executed as long as the condition written after the word is satisfied Bye.

nc Bye condition

loop body

(sequencing)

kts

2. Loop type For - Instructs to execute the loop body for all values ​​of a certain variable (loop parameter) in a given range.

nc For i from i1 before i2

loop body

(sequencing)

kts

PROGRAMMING LANGUAGES

Currently, there are several hundred actually used programming languages ​​in the world. Each has its own area of ​​application.

Any algorithm, as we know, is a sequence of instructions, following which you can move from the initial data to the result in a finite number of steps. Depending on the degree of detail of the instructions, the level of the programming language is usually determined - the less detail, the higher the level of the language.

Programming language(algorithmic language) - a set of rules that determine what sequences of symbols make up a program (syntactic rules) and what calculations the program describes (semantic rules).

Programming languages ​​have the following characteristics:

  • Language level - characterized by the complexity of problems solved using this language.
  • Power of language - characterized by the number and variety of problems, algorithms for solving which can be written using this language.
  • Reliability - the language should provide a minimum of errors when writing programs. Moreover, the language must be such that incorrect programs are difficult to write.
  • Readability b - ease of perception of programs by humans. This characteristic is important during teamwork, when several people work with the same program texts.
  • Completeness - characterizes the ability to describe a class of problems in a certain subject area.
  • Flexibility - characterizes the ease of expression of necessary actions.

Based on this criterion, the following levels of programming languages ​​can be distinguished:

  • machine;
  • machine-oriented (assemblers);
  • machine-independent (high-level languages).

Machine languages ​​and machine-oriented languages ​​are low-level languages ​​that require specifying fine details of the data processing process. High-level languages, on the other hand, imitate natural languages ​​by using some spoken language words and common mathematical symbols. These languages ​​are more human-friendly.

High level languages ​​are divided into:

  • procedural (algorithmic)(Basic, Pascal, C, etc.), which are intended for an unambiguous description of algorithms; to solve a problem, procedural languages ​​require the procedure for solving it to be explicitly written down in one form or another;
  • brain teaser ( Prolog, Lisp, etc. ) , which are focused not on developing an algorithm for solving a problem, but on a systematic and formalized description of the problem so that the solution follows from the compiled description;
  • object-oriented(Object Pascal, C++, Java, etc.), which are based on the concept of an object that combines data and actions on us. A program in an object-oriented language, solving a certain problem, essentially describes a part of the world related to this problem. Describing reality in the form of a system of interacting objects is more natural than in the form of interacting procedures.

Creating a computer program includes the following stages:

§ analysis;

§ design;

§ programming;

§ testing and debugging;

§ exploitation.

To date, there are six generations of programming languages. Each of the subsequent generations is qualitatively different in its functional capacity from the previous one.

  • First generation: Machine languages. Appeared in the mid-40s of the XX century.
  • Second generation: Assemblers. In fact, these are the same machine languages, but more beautifully “wrapped”. Appeared in the late 50s of the XX century
  • Third generation: Procedural languages. Appeared in the early 60s of the XX century. This generation includes universal high-level languages, with the help of which you can solve problems from any area (for example, Algol-60).
  • Fourth generation: Languages ​​for supporting complex data structures(eg SQL). Appeared in the late 60s of the XX century.
  • Fifth generation: Artificial Intelligence Languages(eg Prolog). Appeared in the early 70s of the XX century.
  • Sixth generation: Neural Network Languages(self-learning languages). Research work in this area began in the mid-80s of the 20th century.

CONCLUSION

In order for a computer to perform any task, it needs to execute a specific program. The program must be written according to strict rules, in a form accessible for processing on a computer. Such a set of rules is called a programming language or algorithmic language. Knowing the general principle of constructing and writing computer programs, you can solve almost any problem necessary in the work of information processing.

Algorithmic language – it is a system of notation and rules for uniformly and accurately recording algorithms and their execution. An algorithmic language is a means for writing algorithms in an analytical form, intermediate between writing an algorithm in natural (human) language and writing it in a computer language (programming language).

There is a difference between the concepts of “algorithmic language” and “programming languages”. First of all, a program written in an algorithmic language is not necessarily intended for a computer. The practical implementation of an algorithmic language is a separate issue in each specific case.

Like every language, an algorithmic language has its own vocabulary. The basis of this dictionary is made up of words used to write commands included in the command system of the executor of a particular algorithm. Such commands are called simple commands. In an algorithmic language, words are used, the meaning and method of use of which is specified once and for all. These words are called official. The use of function words makes the recording of the algorithm more visual, and the form of presentation of various algorithms makes it more uniform.

An algorithm written in an algorithmic language must have a name. It is advisable to choose the name so that it is clear what problem this algorithm describes. To highlight the name of the algorithm, write the service word ALG (ALGORITHM) in front of it. Following the name of the algorithm (usually on a new line) are its commands. To indicate the beginning and end of the algorithm, its commands are enclosed in a pair of service words START (START) and CON (END). Commands are written sequentially.

ALG – name of the algorithm

series of algorithm commands

For example, an algorithm that determines the movement of a robot performer may look like:

ALG – to_warehouse

When constructing new algorithms, algorithms compiled earlier can be used. Algorithms that are used entirely as part of other algorithms are called auxiliary algorithms. Any algorithm from a number of previously compiled ones can be auxiliary. It is also possible that an auxiliary algorithm in a certain situation may turn out to be an algorithm that itself contains a link to auxiliary algorithms.

Very often, when compiling algorithms, it becomes necessary to use the same algorithm as an auxiliary one, which, moreover, can be very complex and cumbersome. It would be irrational, when starting work, to compose and remember such an algorithm each time for its subsequent use. Therefore, in practice, so-called built-in (or standard) auxiliary algorithms are widely used, i.e. such algorithms that are constantly available to the performer. Such algorithms are accessed in the same way as “regular” auxiliary algorithms. The robot performer has a built-in auxiliary algorithm that can move to the warehouse from any point in the working field; the executor of the BASIC programming language has, for example, a built-in “SIN” algorithm.

An algorithm may contain a reference to itself as an auxiliary, in which case it is called recursive. If the command for an algorithm to refer to itself is in the algorithm itself, then such recursion is called straight. There may be cases when a recursive call of a given algorithm occurs from an auxiliary algorithm that is called in this algorithm. This recursion is called indirect. Example of direct recursion:

ALG – movement

movement

Algorithms in which the execution order of commands is determined depending on the results of checking certain conditions are called branching. To describe them in an algorithmic language, a special compound command is used - the command branching. In relation to the robot performer, the condition may be to check that the robot is at the edge of the working field (edge/not_edge); checking for the presence of an object in the current cell (yes/not) and some others:

IF condition IF condition IF edge

TO series 1 TO series TO right

OTHERWISE episode 2 EVERYTHING ELSE forward

The following is an algorithmic language entry for the select command, which is a development of the branch command:

WITH condition 1: series 1

UNDER condition 2: series 2

WITH condition N: series N

ELSE series N+1

Algorithms in which individual commands or series of commands are executed repeatedly are called cyclic. To organize cyclic algorithms in an algorithmic language, a special compound loop command is used. It corresponds to block diagrams of the “iteration” type and can take the following form:

BYE condition NC

series BEFORE condition

An algorithm is an accurate and understandable instruction for the performer to perform a sequence of actions aimed at solving a given problem.

The name "algorithm" comes from the Latin form of the name of the Central Asian mathematician al-Khwarizmi - Algorithmi. Algorithm is one of the basic concepts of computer science and mathematics.

An algorithm executor is some abstract or real (technical, biological or biotechnical) system capable of performing the actions prescribed by the algorithm.

The performer is characterized by:

elementary actions;

command system;

The environment (or setting) is the “habitat” of the performer. For example, for the performer Robot from the school textbook, the environment is an infinite cellular field. Walls and painted cells are also part of the environment. And their location and the position of the Robot itself determine the specific state of the environment.

Each executor can execute commands only from a certain strictly defined list - the system of executor commands. For each command, the conditions of applicability must be specified (in which environmental states the command can be executed) and the results of executing the command must be described. For example, the Work command “up” can be executed if there is no wall above the Work. Its result is the displacement of the Robot one cell up.

After calling the command, the performer performs the corresponding elementary action.

Executor failures occur if a command is called in an environment state that is unacceptable for it.

Usually the performer knows nothing about the purpose of the algorithm. He carries out all the commands he receives without asking why or why.

In computer science, the universal executor of algorithms is the computer.

The main properties of the algorithms are as follows:

Understandability for the performer - i.e. The executor of the algorithm must know how to execute it.

Discreteness (discontinuity, separateness) - i.e. The algorithm must represent the process of solving a problem as a sequential execution of simple (or previously defined) steps (stages).

Certainty - i.e. Each rule of the algorithm must be clear, unambiguous and leave no room for arbitrariness. Thanks to this property, the execution of the algorithm is mechanical in nature and does not require any additional instructions or information about the problem being solved.

Effectiveness (or finitude). This property is that the algorithm must lead to solving the problem in a finite number of steps.

Mass character. This means that the algorithm for solving the problem is developed in a general form, i.e. it should be applicable for a certain class of problems that differ only in the initial data. In this case, the initial data can be selected from a certain area, which is called the area of ​​applicability of the algorithm.

In practice, the most common forms of presenting algorithms are:

verbal (recordings in natural language);

graphic (images from graphic symbols);

pseudocodes (semi-formalized descriptions of algorithms in a conventional algorithmic language, including both elements of a programming language and natural language phrases, generally accepted mathematical notations, etc.);

software (texts in programming languages).

The verbal way of writing algorithms is a description of the successive stages of data processing. The algorithm is specified in a free form in natural language.

For example. Write down an algorithm for finding the greatest common divisor (GCD) of two natural numbers.

The algorithm could be as follows:

set two numbers;

if the numbers are equal, then take any of them as the answer and stop, otherwise continue executing the algorithm;

determine the largest of the numbers;

replace the larger number with the difference between the larger and smaller numbers;

repeat the algorithm from step 2.

The described algorithm is applicable to any natural numbers and should lead to a solution to the problem. Convince yourself of this by using this algorithm to determine the greatest common divisor of the numbers 125 and 75.

The verbal method is not widespread for the following reasons:

such descriptions are not strictly formalized;

suffer from verbosity of entries;

allow for ambiguity in the interpretation of individual instructions.

The graphical way of presenting algorithms is more compact and visual compared to the verbal one.

When presented graphically, the algorithm is depicted as a sequence of interconnected functional blocks, each of which corresponds to the execution of one or more actions.

This graphical representation is called a flowchart or flowchart.

In the flowchart, each type of action (entering initial data, calculating the values ​​of expressions, checking conditions, controlling the repetition of actions, completing processing, etc.) corresponds to a geometric figure represented as a block symbol. Block symbols are connected by transition lines that determine the order in which actions are performed.

Table 1 shows the most commonly used symbols.

The "process" block is used to denote an action or sequence of actions that changes the meaning, form of presentation or placement of data. To improve the clarity of the diagram, several individual processing blocks can be combined into one block. The presentation of individual operations is quite free.

The "decision" block is used to indicate conditional control transitions. Each "solution" block must identify the question, condition, or comparison that it defines.

The "modification" block is used to organize cyclic structures. (The word modification means modification, transformation). A cycle parameter is written inside the block, for which its initial value, boundary condition and step of changing the parameter value are indicated for each repetition.

The "predefined process" block is used to indicate calls to auxiliary algorithms that exist autonomously in the form of some independent modules, and for calls to library routines.

Pseudocode is a system of notations and rules designed to uniformly write algorithms.

It occupies an intermediate place between natural and formal languages.

On the one hand, it is close to ordinary natural language, so algorithms can be written and read in it like regular text. On the other hand, pseudocode uses some formal constructs and mathematical symbolism, which brings the algorithm notation closer to the generally accepted mathematical notation.

In pseudocode, strict syntactic rules for writing commands inherent in formal languages ​​are not adopted, which makes it easier to write the algorithm at the design stage and makes it possible to use a wider set of commands designed for an abstract executor. However, pseudocode usually contains some constructs that are inherent in formal languages, which makes it easier to move from writing in pseudocode to writing an algorithm in a formal language. In particular, in pseudocode, as well as in formal languages, there are function words, the meaning of which is determined once and for all. They appear in bold in printed text and are underlined in handwritten text. There is no single or formal definition of pseudocode, so various pseudocodes are possible, differing in the set of function words and basic (basic) constructions.

An example of pseudocode is the school algorithmic language in Russian notation (school AYA), described in the textbook by A.G. Kushnirenko et al. “Fundamentals of Informatics and Computer Science”, 1991. In the future we will simply call this language “algorithmic language”.

Basic function words

General view of the algorithm:

alg name of the algorithm (arguments and results)

conditions for the applicability of the algorithm are given

you need the goal of executing the algorithm

initial description of intermediate quantities

| sequence of commands (body of the algorithm)

The part of the algorithm from the word alg to the word beg is called the header, and the part contained between the words beg and end is the body of the algorithm.

In the alg sentence, after the name of the algorithm, the characteristics (arg, res) and value type (integer, thing, sim, lit or log) of all input (arguments) and output (results) variables are indicated in parentheses. When describing arrays (tables), the service word tab is used, supplemented by boundary pairs for each index of the array elements.

Example sentences alg:

alg Volume and area of ​​the cylinder (arg things R, H, res things V, S)

alg Roots KvUr(arg things a, b, c, res things x1, x2, res lit t)

alg Exclude element(arg int N, arg res stuff tab A)

alg Diagonal(arg int N, arg int tab A, res lit Answer)

Suggestions given and must are not binding. It is recommended to write down statements describing the state of the environment of the algorithm executor, for example:

alg Replacement (arg lit Str1, Str2, arg res lit Text)

given | the lengths of the substrings Str1 and Str2 are the same

need | Everywhere in the Text line, the substring Str1 is replaced by Str2

alg Number of maxima (arg int N, arg thing tab A, res int K)

given | N>0

need | K - the number of maximum elements in table A

alg Resistance (args things R1, R2, args int N, res things R)

given | N>5, R1>0, R2>0

need | R - circuit resistance

Here in sentences given and necessary after the sign "|" comments recorded. Comments can be placed at the end of any line. They are not processed by the translator, but make the algorithm much easier to understand.

Algorithms can be thought of as certain structures consisting of individual basic (i.e. basic) elements.

Naturally, with this approach to algorithms, the study of the basic principles of their design should begin with the study of these basic elements.

To describe them we will use the language of algorithm diagrams and the school algorithmic language.

The logical structure of any algorithm can be represented by a combination of three basic structures:

following,

branching,

A characteristic feature of basic structures is the presence of one input and one output.

Most often, instructions are written in an algorithmic language. It is necessary for precise instructions of all steps and their execution. There are clear differences between school algorithmic language and programming languages. As a rule, the performer in the first option is not only a computer, but also another device that is capable of performing work. Any program written in an algorithmic language does not necessarily need to be executed by technology. The implementation of all instructions in practice is a completely separate issue. Below we will also consider a description of the algorithm in algorithmic language. It will help you understand the structure of this system.

Studying at school

Often, schools teach an algorithmic language, best known as a learning language. It has become widespread due to the fact that it uses words that are as understandable to any student as possible. A similar language with syntax in Russian was introduced a long time ago, namely in the mid-1980s. It was used to provide a basis for schoolchildren and teach them a computer science course without a computer. This language was published in 1985 in one of the textbooks. It was also reprinted several times for special books intended for teaching in grades 9 and 10. The total circulation of the publication was 7 million copies.

Algorithm recording sequence

First of all, you need to write down the letter combination ALG. Next comes the name of the algorithm. Then after the NAC you need to describe a series of commands. The CON statement means the end of the program.

Description of the algorithm in algorithmic language:

ALG Company

START

turn 90 degrees to the left

CON

When writing, keywords must be underlined or in bold. Indentation should be used to indicate logical blocks, and if there are start and end word pairs, a vertical bar should be used to indicate a connection.

Drawing up algorithms

Old records can be used to create new instructions. Such instructions are called auxiliary instructions. A similar algorithm can be any of all those described and compiled earlier. There is also a possibility that this system will additionally use an algorithm that itself has received a reference to auxiliary systems.

Often, when creating instructions, there is a need to use only one algorithm as an additional one. This is why records can often be complex and cumbersome. But it is worth noting that the ability to send a link is simpler than rewriting the same entries several times.

That is why in practice a standard auxiliary algorithm is often used, which is constantly subordinate to the user. The instructions can have a reference either to yourself or to anyone else. Algorithmic language commands are designed for such actions. It is these instructions that are called recursive.

The command to bind to itself is located within the system itself. This recursion is direct. Indirect is considered to be one where the algorithm is called in any other auxiliary instruction.

Algorithms that have a certain order of commands can constantly change depending on the results of executing special parts of the program. Such systems are called branching systems. In order to create them, you must use a special branch command. It has an abbreviated and complete writing scheme. It is not uncommon to find cyclic algorithms that execute specific commands several times.

E-workshop

In order to improve the study of theory in grammatical language, professionals from the Faculty of Mechanics and Mathematics of Moscow State University created a special compiler in 1985. It was called "E-workshop". With its help it was possible to enter, change and execute programs. The following year, a specific set of performers was released. We are talking about “Robot”, “Draftsman”, “Two-legged”, “All-terrain vehicle”. This made it possible to implement algorithms simply and easily. This compiler has become very popular and has been used on some computers. For quite a long time, this programming language was refined and changed. In 1990, a later version appeared in a textbook.

Idol

Now the school algorithmic language is experiencing its rebirth, after a special package “Idol” was developed for Windows and Linux. The system operates with several executors. The classic ones among them are “Robot”, “Draftsman”. The same package is included in the Linux “School” installation file. This system was developed specifically for the Russian Academy of Sciences. It is distributed freely and freely. Over the past few years, the described language has been actively proposed to be used in the Unified State Examination as one of

Language purpose

Algorithmic language is used to solve a fairly wide range of problems. It is suitable for mastering both mathematical and exercises in other subjects. It should be noted that it is also used to make it easier for schoolchildren to study such topics.

Differences between machine and algorithmic languages

The most famous representative of machine-dependent languages ​​is “Assembler”. During programming on it, a person must clearly indicate to the translator, thanks to special operators, which memory cells should be filled or transferred. Since the syntax of “Assembler” is as close as possible to the computer form of notation, it is quite difficult to study it. This is why algorithmic language is taught at school, as well as at the beginning of programming training in the first year of higher education.

Standard Features

The algorithmic language has special standard functions that have received the status of “built-in”. It is thanks to them that you can easily write many operations with numbers and expressions without performing routine entries. The program in an algorithmic language is quite simple. Standard functions can allow you to calculate square roots, logarithms, modulus, and so on. The most popular built-in methods are the following:

  • absolute module abs(X);
  • square root sqrt(X);
  • natural and ln(X), lg(X);
  • minimum and maximum min (X,Y), max (X, Y);
  • trigonometric functions sin(X), cos(X), tan(X), cot(X).

Thanks to this, any programmer or just a person who is learning how to work with an algorithmic language can easily write a mathematical problem without having to reinvent the wheel. Thus, it should be noted that this language is quite convenient. It is easy to understand and also as easy to understand as possible. No wonder it was included in the school curriculum. Schoolchildren enjoy studying it.



Have questions?

Report a typo

Text that will be sent to our editors: