Linear Algorithms - Diagram, Structure and Computation

Every person’s daily life consists in solving a huge number of tasks of varying complexity at work or while studying. Some tasks are so simple that when they are performed, we do certain actions automatically, without even thinking. The solution to any problem, even the simplest, as a rule, is carried out sequentially in several steps. This kind of sequence in solving problems is called an algorithm. Today we will consider what linear algorithms are, how their structure is depicted, how their solution and programming is carried out.

Algorithmic language

This concept is an exact instruction for the contractor to perform a certain sequence of actions, which is aimed at solving the task.

linear algorithms

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

Speaking in computer language, the exact prescription that defines the computing process is indicated. It, in turn, leads from the initial data, which vary, to the original result.

Algorithm development is a rather complicated and laborious process. It is a technique for compiling (developing) a sequence of actions intended to solve problems using a computer.

Algorithm Properties

Among the properties distinguish:

  • finiteness — consists in completing the work of the entire algorithm in a definitely finite number of stages (steps);
  • certainty (uniqueness) - is the uniqueness of the interpretation of the rules for the implementation of actions, as well as the order of their implementation;
  • effectiveness - obtaining the desired result for any finite number of steps;
  • understandability - instructions should be clear to the contractor;
  • mass - algorithms should be able to solve a whole class of specific problems with a general statement of the problem.

Linear Algorithms 9th grade computer science

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

linear algorithm solution

  • linear;
  • branching;
  • with a cycle.

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

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

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

  • Start.
  • Get up
  • Take charge.
  • Wash yourself.
  • Get dressed.
  • Have breakfast.
  • Pack a briefcase.
  • The end.

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

linear computer science algorithms

Linear flowchart algorithm

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

  • Block start-end algorithm. On the block is the inscription "start" or "end".
  • Block "input-output data". This block is depicted as a parallelogram. The following inscriptions are placed on it: “input”, “output”, “print”. They are also accompanied by a list of input or output variables.
  • Arithmetic block, or decision block. A rectangle corresponds to it. On the block there should be an inscription: "operation", "group of operations".

Here with the help of such flowcharts the solution of linear algorithms is depicted. Next, let's talk about the features of value assignment.

Linear Computing Algorithms

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

Linear Algorithm Solution Example

Let us give an example of the description of the rules for the division of ordinary fractions using the 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 down a fraction in which the numerator is the result of 1 point and the denominator is the result of 2 points. The algebraic form of this rule has the following form:

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

linear structure of the algorithm

So, we will build a computer for the fraction division algorithm. In order not to get confused, we will use the same notation for the 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 integer values. The decision in the algorithmic language will be as follows:

alg Fraction Division

the beginning

int a, b, c, d, m, n

input a, b, c, d

m: = a * d

n: = b * s

output m, n

con

Graphic solution form

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

linear algorithm circuit

The value assignment command has the following format:

Variable: = expression.

The sign “: =” is read as assign.

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

  • expression calculations;
  • assignment of the variable to the obtained value.

The above algorithm contains two commands as an assignment. In the flowchart, the assignment command needs to be written in a rectangle called a compute block.

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

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

Enter a, b, c, d.

The input command in the block diagram is written in the parallelogram, that is, in the input-output block. By executing this command, the processor stops working 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 enter key. It is important that the values ​​are entered in the same order as the corresponding variables in the input list.

Linear algorithm. Its programming

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

  • assignment;
  • input;
  • output.

That is, using the operators listed above, linear algorithms are programmed .

So, the assignment operator in a programming 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 is as follows:

INPUT, for example: INPUT C

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

PRINT. For example, PRINT C.

We 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

linear computational algorithms

In a programming language we get a program whose text is shown below.

programming linear algorithms

Input, output operators in the Pascal programming language

Pascal does not allocate special operators denoting input or output operations that use linear algorithms. In programs, information is exchanged using built-in procedures. Since there is no need for a preliminary description of the standard procedure, it is available to every program containing a call to it. Also, the name of the procedure mentioned is not a reserved word.

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

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

Readlnn (x1, y, x2) - when finished, the cursor goes to the beginning of a new line.

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

The output to the data monitor screen is carried out using the following operators:

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

Writeln (z, y, z2) - having finished the output of values, the cursor at this position will move to a new line.

Writeln - indicates skipping one line and switching to the beginning of a new one.

It is with the help of such simple operators that data are entered and output in Pascal.


All Articles