Automobile site - Behind the wheel

Automobile site - Behind the wheel

» Algorithms and data structures for beginners: complexity of algorithms. Algorithm concept

Algorithms and data structures for beginners: complexity of algorithms. Algorithm concept

Almost everything in our world is subject to some kind of laws and rules. Modern science does not stand still, thanks to which mankind knows a lot of formulas and algorithms, following which it is possible to calculate and recreate many actions and structures created by nature, and bring to life ideas invented by man.

In this article we will look at the basic concepts of the algorithm.

History of the appearance of algorithms

Algorithm is a concept that appeared in the 12th century. The word “algorithm” itself comes from the Latin interpretation of the name of the famous Middle Eastern mathematician Muhammad al-Khwarizmi, who wrote the book “On Indian Calculus.” This book describes how to correctly write natural numbers using Arabic numerals, and provides a description of the algorithm for working with a column over such numbers.

In the 12th century, the book “On Indian Accounting” was translated into Latin, and it was then that this definition appeared.

Interaction of the algorithm with man and machine

Creating an algorithm requires creativity, so only a living creature can create a new list of sequential actions. But to carry out already existing instructions, you don’t need to have imagination; even soulless technology can handle this.

An excellent example of following instructions exactly is an empty microwave oven that continues to operate despite there being no food inside.

A subject or object that does not need to understand the essence of the algorithm is called a formal executor. A person can also become a formal executor, but if a particular action is unprofitable, a thinking executor can do everything in his own way. Therefore, the main performers are computers, microwave ovens, telephones and other equipment. The concept of algorithm in computer science is of the most importance. Each algorithm is compiled with a specific subject in mind, taking into account acceptable actions. Those objects to which the subject can apply instructions constitute the executor's environment.

Almost everything in our world is subject to some kind of laws and rules. Modern science does not stand still, thanks to which mankind knows a lot of formulas and algorithms, following which it is possible to calculate and recreate many actions and creations of nature and bring to life ideas invented by man. In this article we will look at the basic concepts of the algorithm.

What is an algorithm?

Most of the actions that we perform during our lives require compliance with a number of rules. The quality and result of completing the tasks assigned to him depends on how correct a person has an idea of ​​what, how and in what sequence he should do. Since childhood, parents have been trying to develop an algorithm for their child’s basic actions, for example: waking up, making the bed, washing and brushing teeth, doing exercises, having breakfast, etc., a list that a person carries out all his life in the morning can also be considered a kind of algorithm.

Which method will be used depends on several factors: the complexity of the problem, how detailed the process of solving the problem needs to be, etc.

Graphical version of the algorithm

A graphical algorithm is a concept that implies the decomposition of actions that need to be performed to solve a certain problem into certain geometric shapes.

They are not depicted haphazardly. In order for anyone to understand them, block diagrams and Nussi-Schneiderman structure diagrams are most often used.

Also, block diagrams are depicted in accordance with GOST-19701-90 and GOST-19.003-80.
Graphic figures used in the algorithm are divided into:

    Basic. Basic images are used to indicate the operations needed to process data when solving a problem.

    Auxiliary. Auxiliary images are needed to indicate individual, not the most important, elements of solving a problem.

In a graphical algorithm, the blocks used to represent data are called blocks.

All blocks go in the sequence “from top to bottom” and “from left to right” - this is the correct direction of flow. With the correct sequence, the lines connecting the blocks do not show direction. In other cases, the direction of the lines is indicated using arrows.

A correct algorithm scheme should not have more than one output from processing blocks and less than two outputs from blocks responsible for checking the fulfillment of conditions.

How to build an algorithm correctly?

The structure of the algorithm, as mentioned above, must be built in accordance with GOST, otherwise it will not be understandable and accessible to others.

The general recording methodology includes the following points:

A name that will make it clear what problem can be solved using this scheme.

Each algorithm must have a clearly defined beginning and end.

Algorithms must clearly and clearly describe all data, both input and output.

When compiling an algorithm, you should note the actions that will allow you to perform the actions necessary to solve the problem on the selected data. An example of the algorithm:

  • Schema name.
  • Data.
  • Start.
  • Teams.
  • End.

Correct construction of the circuit will greatly facilitate the calculation of algorithms.

Geometric shapes responsible for various actions in the algorithm

A horizontal oval is the beginning and the end (a sign of completion).

A horizontal rectangle is a calculation or other action (process sign).

Horizontal parallelogram - input or output (data sign).

A horizontally located rhombus is a condition check (solution sign).

An elongated, horizontally located hexagon is a modification (a sign of preparation).

The algorithm models are presented in the figure below.

Formula-verbal version of constructing an algorithm.

Formula-verbal algorithms are written in free form, in the professional language of the field to which the problem relates. Description of actions in this way is carried out using words and formulas.

The concept of an algorithm in computer science

In the computer field, everything is based on algorithms. Without clear instructions entered in the form of a special code, not a single technique or program will work. In computer science lessons, students are taught the basic concepts of algorithms, taught how to use them and how to create them themselves.

The creation and use of algorithms in computer science is a more creative process than, for example, following instructions for solving a problem in mathematics.

There is also a special program called “Algorithm”, which helps people who are not familiar with programming to create their own programs. Such a resource can become an indispensable assistant for those who are taking their first steps in computer science and want to create their own games or any other programs.

On the other hand, any program is an algorithm. But if the algorithm contains only actions that need to be performed by inserting your data, then the program already contains ready-made data. Another difference is that a program can be patented and is proprietary, but an algorithm cannot. An algorithm is a broader concept than a program.

Conclusion

In this article, we examined the concept of an algorithm and its types, and learned how to correctly write graphic diagrams.

CONCEPT OF ALGORITHM.

PROPERTIES OF THE ALGORITHM. TYPES OF ALGORITHMS. METHODS OF DESCRIBING ALGORITHMS

An algorithm is a precise and understandable instruction to a performer to perform a sequence of actions aimed at solving a given problem. The word “algorithm” comes from the name of the mathematician Al Khorezmi, who formulated the rules for performing arithmetic operations. Initially, an algorithm meant only the rules for performing four arithmetic operations on numbers. Later, this concept began to be used in general to denote the sequence of actions leading to the solution of any given task. When talking about the algorithm of the computational process, it is necessary to understand that the objects to which the algorithm was applied are data. An algorithm for solving a computational problem is a set of rules for converting source data into results. Main

  1. properties
  2. algorithms are:
  3. determinism (certainty). It assumes obtaining an unambiguous result of a computational process with given initial data. Due to this property, the process of executing the algorithm is mechanical in nature;
  4. effectiveness.

Indicates the presence of such initial data for which the computational process implemented according to a given algorithm must stop after a finite number of steps and produce the desired result;

mass character. This property implies that the algorithm should be suitable for solving all problems of a given type;

Block diagram is a graphical representation of the logical structure of an algorithm, in which each stage of the information processing process is represented in the form of geometric symbols (blocks) that have a certain configuration depending on the nature of the operations performed. The list of symbols, their names, the functions they display, shape and dimensions are determined by GOSTs.

With all the variety of algorithms for solving problems, three main types of computational processes can be distinguished:

  • linear;
  • branching;
  • cyclical.

Linear is a computational process in which all stages of solving a problem are performed in the natural order of recording these stages.

Branching is a computational process in which the choice of direction for processing information depends on the initial or intermediate data (on the results of checking the fulfillment of any logical condition).

A cycle is a section of calculations that is repeated many times. A computational process containing one or more cycles is called cyclical .

Based on the number of executions, cycles are divided into cycles with a certain (predetermined) number of repetitions and cycles with an indefinite number of repetitions. The number of repetitions of the latter depends on the satisfaction of some condition specifying the need to execute the cycle. In this case, the condition can be checked at the beginning of the cycle - then we are talking about a cycle with a precondition, or at the end - then it is a cycle with a postcondition.

Algorithm-

-a system of precise and understandable instructions, a defined sequence of elementary operations on initial data, the implementation of which ensures the solution of problems of this type. Algorithm properties:

-discreteness- the sequence of problem solving (process) must be divided into a sequence of individual steps.

-clarity- the algorithm must be understandable to the performer. In this regard, the algorithm must be developed with a focus on the specific performer, i.e. The algorithm can include commands from the command systems of a given executor.

-determinism- being understandable, the algorithm should not contain commands whose meaning can be perceived ambiguously. Violation of these requirements by the compilers of algorithms leads to the fact that the same program, when executed by different executors, does not produce the same results.

-mass character- suitability of the algorithm for solving problems of a certain class.

Ways to write the algorithm:

-verbal– natural language method.

-graphic-description of the algorithm using diagrams.

The process of executing operations or groups of operations

input of initial data, output of results

Decision - choice of direction of execution

Modification is the execution of operations that change commands or groups of commands that change programs.

Line connectors on one page.

Interpage connectors.

-programming language– convenient for entering into a computer.

-pseudocode is a language that uses the structure and syntax of a fairly formalized language and at the same time allows for constructions of natures. Language.

Types of algorithms and basic principles for composing algorithms.

-Linear– an algorithm in which commands are executed sequentially one after another in the order of their natural occurrence, regardless of any conditions. S1, s2, S3…Sn

-branching (branching)- this is a process in which its implementation occurs in one of several predetermined directions, depending on the initial data or intermediate results.

Full conditional construction (full branching)

· Incomplete conditional construction

· Select from several

-cyclical– an algorithm in which a sequence can be executed more than once.

Loop with parameter

· Loop with precondition. It may never be executed. The body of the loop must contain an operator that changes the value of a variable included in block Q.

· Loop with postcondition. Executes at least once.

Basic principles of algorithmization:

1. Identify the source data, results and assign names to them.

2. Problem solving method.

3. Divide the method of solving problems into stages.

4. With a graph representation of the algorithm, each stage is in the form of a corresponding block - a diagram of the algorithm and the order of their execution is indicated by communication lines.

5. In the resulting scheme for any calculation option.

Provide for the issuance of results or messages about their absence.

Provide opportunities after performing any operation to somehow move to the end block.

40.Basic algorithmic structures

We have already looked at the basic concepts of programming and are moving a little closer to the point (but only closer, we will program later).

Let's look at the main structures of the algorithms, and there are six of them:

· Following. This is a sequence of blocks (or groups of blocks) of an algorithm. In the program, following is presented in the form of sequential execution of operations

·
Branching. This algorithmic structure is used when, depending on the condition, it is necessary to perform one or another action

·
Bypass. This structure is a special case of branching, when there is no action in one of the branches.

·
Multiple choice. This structure is a generalization of branching, where it is necessary to perform one of several actions depending on the value of the variable A.

Before we start writing super programs, let's figure out what a program is? A program is a specific algorithm that your computer must execute.

Well, now the main question: What is an algorithm?

Properties of algorithms

I will not reinvent the wheel, but will simply list the properties of the algorithm that have been known for many years.

  1. Extremity (effectiveness) algorithm means that a result must be obtained in a finite number of steps;
  2. Discreteness algorithm means that the algorithm must be broken down into a sequence of steps;
  3. Understandability algorithm means that the algorithm must contain only those commands that are included in the set of commands that a specific executor can execute;
  4. Accuracy algorithm means that each command must be understood unambiguously;
  5. Mass character algorithm means that, once compiled, the algorithm must be suitable for solving similar problems with different initial data.
  6. Determinism (certainty). An algorithm has the property of determinism if for the same sets of initial data it produces the same result, i.e. the result is uniquely determined by the initial data.

Thus, Algorithm- this is a clear and precise instruction to the performer to perform a final sequence of steps leading from the initial data to the desired result.

Imagine that I have to cut an orange with a knife. To perform this action I need an algorithm.


I want to cut an orange. How to do it?

Types of algorithms

    • Linear (Commands are sequential without repetitions or transitions);

Algorithm example:

Start
take out the knife
cut an orange (It’s an orange, not any other fruit. ACCURACY is responsible for this)
eat an orange
end

    • Cyclic (There is a group of actions that are repeated according to some condition);

Algorithm example:

Start
take out the knife
UNTIL the oranges are gone
cut an orange
eat all the oranges
end

    • Branching (Command execution depends on a condition).

Algorithm example:

Start
take out the knife
IF the knife is dull, sharpen it
cut an orange
eat an orange
end

That's all. In the next lesson we will look at the structure of a program in Pascal.

There is no single “true” definition of the concept “algorithm”.

“An algorithm is a finite set of rules that defines a sequence of operations to solve a specific set of problems and has five important features: finiteness, certainty, input, output, efficiency.” (D. E. Knuth)

“An algorithm is any system of calculations performed according to strictly defined rules, which after a certain number of steps obviously leads to the solution of the problem.” (A. Kolmogorov)

“An algorithm is a precise prescription that defines a computational process that goes from varying initial data to the desired result.” (A. Markov)

“An algorithm is a precise prescription for performing in a certain order a certain system of operations leading to the solution of all problems of a given type.” (Philosophical Dictionary / Edited by M. M. Rosenthal)

“An algorithm is a strictly deterministic sequence of actions that describes the process of transforming an object from the initial state to the final state, written using commands understandable to the performer.” (Nikolai Dmitrievich Ugrinovich, textbook “Informatics and information technology”)

“An algorithm is a sequence of actions aimed at obtaining a certain result in a finite number of steps.”

“An algorithm is an unambiguous, accessible and briefly (conventional concepts - stage names) described sequence of procedures for reproducing a process with a result determined by the task of the algorithm under given initial conditions. The universality (or specialization) of an algorithm is determined by the applicability and reliability of this algorithm for solving non-standard problems.”

“An algorithm is clear and precise instructions to the performer to take a finite number of steps aimed at solving a given problem.”

“An algorithm is a certain finite set of operations designed for a specific performer, as a result of which, after a certain number of steps, a given goal can be achieved or a problem of a certain type can be solved.”

“An algorithm is a sequence of actions that either leads to a solution to a problem or explains why this solution cannot be obtained.”

“An algorithm is an exact, unambiguous, finite sequence of actions that a user must perform to achieve a specific goal or to solve a specific task or group of tasks.”

“An algorithm is a precise prescription that specifies a computational (algorithmic) process, starting with an arbitrary initial data and aimed at obtaining a result completely determined by this initial data.”

Algorithm properties

Various definitions of an algorithm, either explicitly or implicitly, contain the following series of general requirements:

  1. Discreteness- the algorithm must represent the process of solving a problem as a sequential execution of some simple steps. Moreover, each step of the algorithm requires a finite period of time to complete, that is, the transformation of the source data into the result is carried out discretely in time.
  2. Determinism- certainty. At each moment in time, the next step of work is uniquely determined by the state of the system. Thus, the algorithm produces the same result (answer) for the same initial data. In the modern interpretation, different implementations of the same algorithm must have an isomorphic graph. On the other hand, there are probabilistic algorithms in which the next step of work depends on the current state of the system and the generated random number. However, when the method of generating random numbers is included in the list of “initial data”, the probabilistic algorithm becomes a subtype of the usual one.
  3. Understandability- the algorithm for the performer should include only those commands that are available to him (the performer), which are included in his command system.
  4. Limb- with correctly specified initial data, the algorithm must complete its work and produce a result in a finite number of steps. On the other hand, a probabilistic algorithm may never produce a result, but the probability of this is 0.
  5. Mass character- the algorithm must be applicable to different sets of source data.
  6. Efficiency- completion of the algorithm with certain results.
  7. An algorithm contains errors if it produces incorrect results or does not produce results at all.
  8. An algorithm is error-free if it produces correct results for any valid input data.

Types of algorithms

Main types of algorithms:

1)Applied Algorithms - designed to solve certain applied problems.

An algorithm is considered correct if it meets the requirements of the task (for example, it gives a physically plausible result. An algorithm (program) contains errors if for some initial data it gives incorrect results, failures, failures, or does not give any results at all.

2)Recursive Algorithms - algorithms that call themselves until some return condition is reached.

3) Starting from the end of the 20th - beginning of the 21st century, they have been actively developing parallel algorithms - designed for computers capable of performing several operations simultaneously.

Ways to describe algorithms

The algorithm can be written in words and depicted schematically. Usually, at first (at the level of the idea), the algorithm is described in words, but as it approaches implementation, it acquires more and more formal outlines and formulation in a language understandable to the performer (for example, machine code). For example, flowcharts are used to describe an algorithm. Another description option, independent of the programming language, is pseudocode.

Literature

  1. Thomas H. Corman, Charles I. Leiserson, Ronald L. Rivest, Clifford Stein Algorithms: construction and analysis = INTRODUCTION TO ALGORITHMS. - 2nd ed. - M.: “Williams”, 2006. - P. 1296.
  2. Donald Knuth The Art of Computer Programming, volume 1. Basic Algorithms = The Art of Computer Programming, vol.1. Fundamental Algorithms. - 3rd ed. - M.: “Williams”, 2006. - P. 720.
  3. Porublev Ilya Nikolaevich, Stavrovsky Andrey Borisovich Algorithms and programs. Solving Olympiad problems. - M.: “Williams”, 2007. - P. 480.