EducationSecondary education and schools

Types of algorithms in computer science: examples

When studying computer science, much attention is paid to the study of algorithms and their types. Not knowing the basic information about them, you can not 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 the algorithm, the properties of the algorithm, and the types.

The concept of

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

Quite often, algorithms are used in mathematics to solve certain problems. So, many 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 clarify their basic properties.

Among the basic properties of algorithms it is necessary to allocate the following:

  • Determination, that is, certainty. It means that any algorithm assumes the receipt of a definite result for given initial ones.
  • Effectiveness. Means that if there are a number of input data after a number of steps, a certain, expected result will be achieved.
  • The mass. Once-written algorithm 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.

Ways to write

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

  1. The word.
  2. Formally word-based.
  3. Graphic.
  4. The language of the algorithm.

Most often, the algorithm is represented in the form of a block diagram, using special notations fixed by GOSTs.

Basic views

There are three main schemes:

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

Next, we'll look at 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 the linear algorithm. It involves a sequence of actions. We give the simplest example of an algorithm of this kind. Let's call it "Gathering to school".

1. We get up when the alarm goes off.

2. We wash.

3. Brush your teeth.

4. We do exercises.

5. Dressing.

6. We eat.

7. We study and go to school.

8. The end of the algorithm.

Branching Algorithm

Considering the types of algorithms in computer science, one can not help recalling the branching structure. This type assumes that there is an condition in which, in the event of its execution, the actions are performed in one order, and in case of failure, in the other.

For example, let's take the following situation: crossing the road by a pedestrian.

1. We approach the traffic lights.

2. Look at the traffic light 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 light comes on.

4.2 Cross the road.

5. The end of the algorithm.

Cyclic Algorithm

Studying the types of algorithms in computer science, we should dwell in detail on the cyclic algorithm. The given algorithm assumes a site of calculations or actions which is carried out before performance of a certain condition.

Let's take a simple example. If a series of numbers from 1 to 100. We need to find all the prime numbers, that is, those that are divided into one and oneself. We call the algorithm "Prime numbers".

1. Take the number 1.

2. We check if it is less than 100.

3. If so, do we check whether this is a simple number.

4. If the condition is met, write it down.

5. We take the number 2.

6. We check if it is less than 100.

7. We check whether it is simple.

.... We take the number 8.

We check if it is less than 100.

We check whether the number is prime.

No, we miss it.

We take the number 9.

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

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

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

Other options

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

Notation in flowchart

We have examined what kinds of algorithms are in computer science. But we did not talk about what notation is used when they are recorded graphically.

  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 prescribed in the rhombus.
  4. All parts of the algorithm are connected using arrows.

conclusions

We have considered the topic "Algorithms, types, properties". Informatics devotes considerable time to studying algorithms. They are used when writing various programs for solving mathematical problems, and for creating games and various kinds of applications.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.