Types of algorithms in computer science: examples

Table of contents:

Types of algorithms in computer science: examples
Types of algorithms in computer science: examples
Anonim

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

Concept

An algorithm is a certain sequence of actions that leads to the achievement of a particular result. When compiling an algorithm, each action of the performer is prescribed in detail, which will later lead him to solve the problem.

Image
Image

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 a discriminant.

Properties

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

Among the main properties of algorithms, the following should be highlighted:

  • Determinism, i.e.certainty. It lies in the fact that any algorithm involves obtaining a certain result for given initial ones.
  • Productivity. It means that if there is a series of initial data, after performing a series of steps, a certain, expected result will be achieved.
  • Mass character. 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.

Writing methods

No matter what kinds of computer science algorithms you consider, there are several ways to write them.

  1. Verbal.
  2. Formulative-verbal.
  3. Graphic.
  4. Algorithm language.

The algorithm is most often depicted in the form of a block diagram, using special designations fixed by GOSTs.

Main species

There are three main schemes:

  1. Linear algorithm.
  2. Branching algorithm, or branching.
  3. Cyclic.

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

Linear

Image
Image

The simplest in computer science is the linear algorithm. It assumes a sequence of actions. Let us give the simplest example of an algorithm of this kind. Let's call it "School collection".

1. We get up when the alarm rings.

2. Washing up.

3. Brushing our teeth.

4. We do exercises.

5. Getting dressed.

6. Eating.

7. Put on shoes and go to school.

8. End of algorithm.

Branching algorithm

Image
Image

When considering the types of algorithms in computer science, one cannot but recall the branching structure. This type assumes the presence of a condition under which, if it is performed, the actions are performed in one order, and in case of failure, in another.

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

1. Approaching the traffic light.

2. We look at the traffic light.

3. It must be green (this is a condition).

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

4.1 If not, wait until the green light turns on.

4.2 Crossing the road.

5. End of algorithm.

Cyclic algorithm

Image
Image

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

Take a simple example. If the series of numbers is from 1 to 100. We need to find all prime numbers, that is, those that are divisible by one and themselves. Let's call the algorithm "Prime Numbers".

1. We 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 met, write it down.

5. We 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.

Checking if a number is prime.

No, skip it.

Take the number 9.

Thus, iterate over all numbers up to 100.

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

Among cyclic algorithms, there are 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.

Other options

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

Notation in the block diagram

We have considered what types of algorithms are in computer science. But we did not talk about what symbols are used in their graphic recording.

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

Conclusions

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

Recommended: