EducationSecondary education and schools

Linear Algorithms - Schema, Structure, and Computation

Everyday life of each person consists in the decision of a huge quantity of problems of various complexity at work or during study. Some tasks are so simple that when they are executed we do certain actions automatically, without even thinking. The solution of any problem, even the simplest, is usually carried out sequentially in several steps. Such a sequence in solving problems is called an algorithm. Today we will consider what linear algorithms are, how their structure is represented, how their solution and programming are carried out.

Algorithmic language

This concept is a precise prescription for the performer to perform a certain sequence of actions, which is directed towards the solution of the task.

This language is a means of describing algorithms that are usually user-oriented.

If we speak in computer language, this is the exact instruction that defines the computational process. It, in turn, leads from the initial data, which varies, to the initial result.

The development of the algorithm is a rather complex and time-consuming process. It is a technique for compiling (developing) a sequence of actions intended for solving problems with the help of a computer.

Algorithm properties

Among the properties are:

  • Finiteness - consists in the completion of the entire algorithm for a definite finite number of steps (steps);
  • Certainty (uniqueness) - is the uniqueness of the interpretation of rules for the performance of actions, as well as the order of their implementation;
  • Effectiveness - obtaining the desired result for any finite number of steps;
  • Clarity - instructions should be clear to the performer;
  • Mass character - algorithms should be able to solve a whole class of specific problems with a general statement of the problem.

Linear Algorithms. Informatics of the 9th grade

We have already considered the definitions and properties of this concept. Now let's talk about its types:

  • linear;
  • Branching;
  • With a cycle.

We are interested in linear algorithms. What are they? They contain commands that must be executed one after another in a clear sequence.

The linear structure of the algorithm can be written in verbal and graphical form.

Here is an example written in verbal form. So, the task: get to school. Decision:

  • Start.
  • Stand up.
  • Do the gymnastics.
  • Wash yourself.
  • Get dressed.
  • Have breakfast.
  • Gather the briefcase.
  • The end.

The graphical form of the above process will present the following:

Linear algorithm in the form of a block diagram

A block diagram is an illustrative representation of an algorithm in which each individual step is represented by blocks represented in a variety of geometric shapes. In addition, the connection between the stages (in other words, the sequence of step-by-step execution) is indicated by the arrows that connect the figures (blocks). Each block is accompanied by an inscription. For typical actions in a linear algorithm, the following geometric shapes are used :

  • Block of the beginning-end of the algorithm. The block contains the inscription "beginning" or "end".
  • Data input / output block. This block is represented as a parallelogram. It contains the following inscriptions: "input", "output", "print". Also, they are accompanied by a list of input or output variables.
  • Arithmetic block, or decision block. It corresponds to a rectangle. On the block there should be an inscription: "operation", "group of operations".

Here, with the help of such block diagrams, the solution of linear algorithms is depicted. Next, let's talk about the features of assigning values.

Linear Computing Algorithms

The basic elementary action in the computational algorithm is the assignment of a variable to a value of a certain value. In the case where the value of the constant is determined by the type of its record, the variable will receive a specific value solely as a result of the assignment. This can be done in two ways: using the assignment command; Using the input command.

Example of solving a linear algorithm

We give an example of the description of the rules for dividing ordinary fractions using a linear algorithm, which in school textbooks have the following content:

  • The numerator of fraction 1 must be multiplied by the denominator of fraction 2;
  • The denominator of fraction 1 must be multiplied by the numerator of fraction 2;
  • It is required to write a fraction whose numerator is the result of the fulfillment of 1 point, and the denominator is the result of the fulfillment of 2 points. The algebraic form of this rule has the following form:

A / b: c / d = (a * d) / (b * d) = m / n.

So, let's build a fractional division algorithm for a computer. In order not to get confused, we will use the same notations for variables as in the formula that was mentioned above. A, b, c, d - initial data in the form of integer variables. The result will also be integers. The solution in the algorithmic language is as follows:

Alg Fission of fractions

Beginning

Integer a, b, c, d, m, n

Input a, b, c, d

M: = a * d

N: = b * s

Output m, n

Con

Graphic form of the solution

The scheme of the linear algorithm described above looks like this:

The value assignment command has the following format:

Variable: = expression.

The sign ": =" is read as assigned.

Assignment is a command that is necessary for the computer to perform the following actions:

  • Evaluating the expression;
  • Assigning a variable to the value obtained.

The above algorithm contains two commands as an assignment. In the block diagram, the assignment command must be written in a rectangle, which is called a computational block.

When linear algorithms are described, there is no particular need for strict observance of strict rules when writing expressions. You can write them using the usual mathematical form. After all, this is not a strict programming language syntax.

In the above example of the algorithm there is also an input command:

Input a, b, c, d.

The input command in the block diagram is written in the parallelogram, that is, in the I / O block. By executing this command, the processor interrupts the operation until the user performs certain actions. Namely: the user needs to type the input variables (their values) on the input device (keyboard) and press Enter, which is the input key. It is important that the values are entered in the same order as the corresponding variables in the input list.

Linear algorithm. His programming

As already mentioned at the beginning of the article, linear programs can include such operators:

  • assignment;
  • Input;
  • conclusion.

That is, with the help of the listed operators, linear algorithms are programmed .

So, the assignment statement in the program language is written like this:

LET A = B, where A is a variable, B is an expression. For example, A = Y + 20.

The input operator has the following form:

INPUT, for example: INPUT C

The operator for outputting data, values, is written in this form:

PRINT. For example PRINT C.

Let's give a simple example. We need to write a program that will find the sum of the numbers A and B entered from the keyboard.

In the programming language, we get a program, the text of which is shown below.

Operators of input, output in the programming language Pascal

Pascal does not distinguish special operators that denote input or output operations that use linear algorithms. In the programs, the information is exchanged using the built-in procedures. Since there is no need for a preliminary description of the standard procedure, it is available to every program that contains access to it. Also, the name of the procedure does not come from any reserved word.

When entering data, these operators are used to access the standard data entry procedure, which is already built into the program.

Read (A, B, C), where A, B, C - variables that need to be entered into the RAM for storage.

Readlnn (x1, y, x2) - after finishing the input, the cursor moves to the beginning of a new line.

Readlnn; - indicates the expectation of pressing "Enter". Typically, this operator is inserted into the text before the last "End" to save the results of the program on the content screen.

The display of the data monitor is carried out with the help of such operators:

Write (A, B, C) - indicating the values of A, B, C in one line, the cursor does not leave the current line.

Writeln (z, y, z2) - after finishing the output of values, the cursor in this position will move to a new line.

Writeln; - indicates the omission of one line and the transition to the beginning of a new one.

Here with the help of such simple operators and input and output data in Pascal.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.unansea.com. Theme powered by WordPress.