You get a bonus - 1 coin for daily activity. Now you have 1 coin

The concept of the algorithm. Execution algorithms. Properties of algorithms. Typical algorithmic structures. Ways to describe algorithms.

Lecture




The concept of the algorithm. Execution algorithms. Properties of algorithms.

The concept of an algorithm is as fundamental to computer science as the concept of information. There are many different definitions of the algorithm, since this concept is quite broad and is used in various fields of science, technology and everyday life.

The algorithm is a clear and precise sequence of actions that describes the process of transforming an object from the initial state to the final state.

The executor of the algorithm can be either a person (cooking recipes, various instructions, algorithms of mathematical calculations) or a technical device. Various machines (computers, industrial robots, modern household appliances) are formal implementers of algorithms. The formal executor is not required to understand the essence of the problem being solved, but the exact execution of the command sequence is required.

The algorithm can be written in various ways (verbal description, graphic description - block diagram, program in one of the programming languages, etc.). A program is an algorithm written in a programming language.

To create an algorithm (program) you need to know:

  • complete set of initial data of the task (initial state of the object);

  • the purpose of the algorithm (the final state of the object);

  • the system of commands of the performer (that is, a set of commands that the performer understands and can execute).

The resulting algorithm (program) must have the following set of properties:

  • discreteness (the algorithm is divided into separate steps - commands);

  • unambiguity (each com *** and defines the only possible action of the performer);

  • clarity (all commands of the algorithm are included in the system of commands of the contractor);

  • effectiveness (the performer must solve the problem in a finite number of steps).

Most of the algorithms also have the property of mass (using the same algorithm, you can solve many of the same type of problems).

Ways to describe algorithms.

It was noted above that the same algorithm can be written in different ways. You can write the algorithm in natural language. In this form, we use recipes, instructions, etc. To write algorithms intended for formal performers, special programming languages ​​have been developed . Any algorithm can be described graphically in the form of a flowchart . For this purpose, a special notation has been developed:

Designation Description Notes
  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. The beginning and end of the algorithm
  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. Input and output data. Data output is sometimes indicated differently:   The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. Act In computational algorithms, the so-called assignment
  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. Fork A fork is a component necessary for the realization of branches and cycles
  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. Start a loop with a parameter
  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. Typical process In programming, procedures or subroutines
  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms. Transitions between blocks

Let us give an example of the description of the algorithm for summing up two quantities in the form of a flowchart:

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

This way of describing the algorithm is the most obvious and understandable to humans. Therefore, algorithms of formal performers are usually developed first in the form of a flowchart, and only then create a program in one of the programming languages.

Typical algorithmic structures.

The programmer has the ability to design and use atypical algorithmic structures, however, this is not necessary. Any arbitrarily complex algorithm can be developed on the basis of three typical structures: following, branching and repeating. In this case, the structures can be placed one after the other or invest in each other.

Linear structure (following).

The simplest algorithmic structure is linear . In it, all operations are performed once in the order in which they are recorded.

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

Branching

In the full branching there are two options for the performer depending on the value of the logical expression (condition). If the condition is true, then only the first branch will be executed, otherwise only the second branch.

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

The second branch may be empty. Such a structure is called incomplete branching or circumvention .

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

From several branches, one can construct a “ choice ” structure (multiple branching), which will choose not from two, but from a larger number of actions of the contractor, depending on several conditions. It is essential that only one branch is fulfilled - in such a structure the order of the conditions is important: if several conditions are fulfilled, then only one of them will work - the first one from above.

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

Loop (repeat).

The cycle allows you to organize multiple repetitions of the same sequence of commands - it is called the body of the cycle. In various types of cyclic algorithms, the number of repetitions can depend on the value of a logical expression (condition) or can be rigidly specified in the structure itself. Distinguish cycles: " d o ", " p oka ", cycles with a counter. In the “before” and “while” cycles, the logical expression (condition) can precede the body of the cycle ( cycle with precondition ) or end the cycle ( cycle with post-condition ).

Cycles " d about " - repeating the body of the cycle until the condition:

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.   The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

P okcycles - repetition of the cycle body while the condition is fulfilled (true):

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.   The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

C cycles with a counter (with a parameter) - repetition of the loop body a specified number of times:

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

Auxiliary algorithm (subroutine, procedure).

The auxiliary algorithm is a module that can be repeatedly accessed from the main algorithm. The use of auxiliary algorithms can significantly reduce the size of the algorithm and simplify its development.

Methods for developing complex algorithms.

There are two methods for developing complex algorithms:

The method of sequential detailing of the task (“top-down”) is that the initial complex task is divided into subtasks. Each of the subtasks is considered and solved separately. If any of the subtasks are complex, they are also broken down into subtasks. The process continues until the subtasks are not elementary. The solutions of individual subtasks are then assembled into a single algorithm for solving the original problem. The method is widely used, since it allows the development of a general algorithm to be carried out simultaneously by several programmers solving local subtasks. This is a prerequisite for the rapid development of software products.

The assembly method (“bottom-up”) is to create a set of software modules that implement the solution of typical problems. When solving a complex problem, the programmer can use the developed modules as auxiliary algorithms (procedures). In many programming systems   similar sets of modules already exist, which greatly simplifies and speeds up the creation of a complex algorithm.

Algorithms and control processes.

Management is the purposeful interaction of objects, some of which are managers, others are managed.

In the simplest case, there are two such objects:

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

From the point of view of computer science, control actions can be considered as control information. Information can be transmitted in the form of commands. The sequence of commands to control an object, leading to a predetermined goal, is called a control algorithm . Consequently, the control object can be called the executor of the control algorithm. In the above example, the control object works "without looking" at what happens to the control object (open -loop control ). This control scheme is called unlocked . Another control scheme may take into account information about the processes occurring in the control object:

  The concept of the algorithm.  Execution algorithms.  Properties of algorithms.  Typical algorithmic structures.  Ways to describe algorithms.

In this case, the control algorithm must be flexible enough to analyze this information and decide on its further actions depending on the state of the control object ( feedback control ). This control scheme is called closed .

In more detail, control processes are studied are considered cybernetics . This science claims that the most diverse management processes in society, nature, and technology occur in a similar way, subject to the same principles.

 


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Algorithmization and programming. Structural programming. C language

Terms: Algorithmization and programming. Structural programming. C language