Types of algorithms in computer science: examples

In the study of computer science, a lot of attention is paid to the study of algorithms and their types. Without knowing the basic information about them, you cannot write a program or analyze its work. The study of algorithms begins in the school course of computer science. Today we will consider the concept of an algorithm, properties of an algorithm, types.

The concept

An algorithm is a certain sequence of actions that leads to the achievement of a particular result. Composing the algorithm, each action of the executor is prescribed in detail, which in the future will lead him to the solution of the task.

Quite often, algorithms are used in mathematics to solve certain problems. So, many people know the algorithm for solving quadratic equations with the search for discriminant.

The properties

Before considering the types of algorithms in computer science, it is necessary to find out their basic properties.

Among the main properties of the algorithms, it is necessary to highlight the following:

  • Determinism, that is, certainty. It consists in the fact that any algorithm involves obtaining a specific result for a given source.
  • Performance. It means that in the presence of a number of initial data, after a series of steps, a certain, expected result will be achieved.
  • Massiveness. An algorithm written once can be used to solve all problems of a given type.
  • Discreteness. It implies that any algorithm can be divided into several stages, each of which has its own purpose.

Recording Methods

Regardless of what types of algorithms in computer science you are considering, there are several ways to write them.

  1. Verbal.
  2. Formular verbal.
  3. Graphic.
  4. The language of the algorithm.

The algorithm is most often depicted in the form of a flowchart using special notation fixed by GOSTs.

Main types

There are three main schemes:

  1. Linear algorithm.
  2. Branched algorithm, or branched.
  3. Cyclical.

Next, we will consider the types of algorithms in computer science, examples that will help to understand in more detail how they work.

Linear

The simplest in computer science is a linear algorithm. It involves a sequence of actions. We give the simplest example of an algorithm of this kind. We will call it "Gathering to School."

1. We get up when the alarm rings.

2. We wash ourselves.

3. Brush your teeth.

4. Do the exercises.

5. Dress up.

6. We eat.

7. We put on our shoes and go to school.

8. The end of the algorithm.

Branching algorithm

Considering the types of algorithms in computer science, one can not help but recall the branching structure. This type assumes the existence of a condition under which, in case of its fulfillment, the actions are performed in one order, and in case of non-fulfillment, in another.

For example, take the following situation - a pedestrian crossing a road.

1. We approach the traffic light.

2. We look at the traffic signal.

3. It must be green (this condition).

4. If the condition is met, we cross the road.

4.1 If not, wait until the green lights up.

4.2 Cross the road.

5. The end of the algorithm.

Loop algorithm

Studying the types of algorithms in computer science, it is necessary to dwell in detail on the cyclic algorithm. This algorithm assumes a section of calculations or actions that is performed before a certain condition is met.

Take a simple example. If the series of numbers is from 1 to 100. We need to find all the prime numbers, that is, those that are divided by unity and ourselves. We call the algorithm "Prime numbers".

1. Take the number 1.

2. Check if it is less than 100.

3. If yes, check if this number is prime.

4. If the condition is satisfied, write it.

5. Take the number 2.

6. Check if it is less than 100.

7. Check if it is simple.

... Take the number 8.

Check if it is less than 100.

Check if the number is prime.

No, skip it.

Take the number 9.

Thus, we sort through all the numbers, up to 100.

As you can see, steps 1 through 4 will be repeated a number of times.

Among cyclic, algorithms with a precondition when the condition is checked at the beginning of the cycle, or with a postcondition when the check is at the end of the cycle, are distinguished.

Other options

The algorithm can also be mixed. So, it can be cyclic and branched at the same time. In this case, different conditions are used on different segments of the algorithm. Such complex structures are accepted when writing complex programs and games.

Designations in the block diagram

We have examined what types of algorithms are in computer science. But we did not talk about what designations are used when they are graphically written.

  1. The beginning and end of the algorithm are written in an oval frame.
  2. Each command is fixed in a rectangle.
  3. The condition is written in the rhombus.
  4. All parts of the algorithm are connected using arrows.

conclusions

We have examined the topic "Algorithms, types, properties." Computer science devotes a lot of time to studying algorithms. They are used when writing various programs both for solving mathematical problems and for creating games and various kinds of applications.


All Articles