Friday, March 29, 2024

What is a Algorithm?

The word “algorithm” is very common on the Internet, and for many, it is a mystery.

Let’s look at understandable and simple examples with the concept of an algorithm, as well as its types and applications.

Algorithm

Algorithms are all around us. According to their principles, the animal world, people, computers and mechanisms work. Some of them are obvious, while others are hidden from view (but this does not mean that they are not).

“The algorithm in computer science is a sequence of actions that aims to achieve a final solution to a problem in the most optimal and efficient ways

There are complex and easy algorithms. Some require no effort to solve, while others will not be enough even with all the power of computers.

Any actions that involve a certain sequence in the life of animals and people can be called an algorithm (search for food for an animal, going to the store for bread)

Of course, a foraging animal does not suspect that it uses algorithms, but it acts according to certain rules (instincts) in order to get food:

  1. the animal is looking for a place where there is food (using the sense of smell and other senses);
  2. then performs actions to get to the treat;
  3. if successful, eats what is found.

In computer science and programming, algorithms are used to write programs. The better the algorithms used in the program, the better it works

When you start learning any programming language, the first thing they explain to you is the principles of building an algorithm for a future program. These are flowcharts that clearly show the progress of data processing and the logic of calculations. Without them, it will be very difficult to write programs at first.

Kinds and types of algorithms

A linear algorithm is a sequential execution of instructions in a strict order of their location (for example, “make a cheese sandwich”)

Sequencing:

  1. take a piece of bread;
  2. cut off a piece of cheese;
  3. put it on bread.

Branches – a sequence of actions in accordance with certain conditions (if one condition, then action 1 is performed, if another condition, then action 2 is performed)

Example: If it is raining heavily, then take an umbrella, otherwise you do not need to take an umbrella.

In most cases, the word “otherwise” is omitted, since further logic is already clear from the context of the first part of the phrase.

Example: If you want to report something important, call the phone (in this case, obviously, if the message is not important, then you do not need to call).

Cyclic algorithms are a sequence of actions that must be repeated several times to achieve a positive result (“checking pears for rotten and not rotten”)

Example: There are pears in one box, it is necessary to select rotten and good ones. To do this, we perform the following actions:

  1. take a pear from the box;
  2. see if it is rotten or not;
  3. if rotten, then throw it away;
  4. if not, put in another box;
  5. repeat the operation until all the pears in the box have been sorted out.

Sometimes there are situations when the cycle begins to repeat itself endlessly. This is called looping or an infinite loop

This happens when the condition cannot be met, then the loop closes into an infinite repetition. It is worth noting that such situations should be avoided.

In programming languages, there are different kinds of algorithms for solving certain problems.

The main types that every novice programmer should know are those that use sorting and searching methods

Everything that surrounds us is built on these algorithms, they are considered easy to understand.

Where are algorithms used?

In mathematical sciences and computer science, this is the search for an effective solution to a given problem using tools and means.

For example, even when solving a simple problem (2 * 6), certain methods and tools are used to obtain the correct result. The most interesting thing is that it can be solved in several ways: using a piece of paper and a pen, counting on a computer, or doing mental multiplication. The most efficient way to solve this problem will be the best algorithm in this case.

But such simple examples are not very interesting for computer science lovers. There are much more exciting problems that are troubling the minds of many programmers, and scientists all over the world are struggling to solve them.

The task of the seller (traveling salesman)

There are more interesting examples to understand the complexity of the functioning of algorithms. For example, the traveling salesman problem.

Given: one seller needs to visit four cities: for example, Moscow, Berlin, London, and San Francisco. Sell ​​goods there, and then return back.

The solution to the problem looks simple. First, from Moscow, go to Berlin, then visit London, and then go to San Francisco and return to Moscow.

In fact, this is a complex algorithm for a computer. These 4 options hide 24 different travel combinations to solve the problem. The computer calculates the distance from one city to another, then compares the options and comes up with a solution.

But if you increase the number of cities (for example, up to 100), then the computer will not be able to solve this problem, since there will be millions of options, and it will take several centuries to solve.

But the most interesting thing is that, having understood the principle of solving such a problem, it can be extended to all similar ones, which will expand knowledge in the field of computer science And other sciences.

The Turing Machine is the basis for understanding algorithms

This is an abstract machine that was invented by Alan Turing, a famous British scientist. The genius of this machine is as follows. There is a kind of tape, consisting of many individual (infinite) cells that contain data or bits (0 and 1). There is a reader that has access to the tape.

In the process of movement, the device is provided with certain instructions, accesses the cells, reads the information and moves on. But the machine can change its actions, write different information, or move in one direction or the other (based on the stack of internal instructions).

As a result of the research of such machines, Turing put forward the hypothesis that the algorithm, when finding the values ​​of some function that is given in the region of the alphabet, only exists when this function is calculated on the Turing machine

This is an axiom, a postulate, which cannot be proved by a mathematical method, since an algorithm is not an exact mathematical concept.

Conclusion

Learning algorithm is an important part of understanding how computers work. It allows you to find out how the computer functions, how it receives, processes data, and produces the desired result

Understanding the principles of work will help to better master computer languages, since, knowing the principles of constructing and creating effective algorithms, you can learn any programming language (like the alphabet in foreign languages).

Priyanka Sharma
Priyanka Sharma
I am Priyanka, currently dedicating myself entirely to writing for ournethelps.com. In my role as a writer, I am committed to producing content of exceptional quality and collaborate closely with the ONH Team to ensure the delivery of outstanding material. Outside of work, my hobbies include creating humorous videos for my Instagram, YouTube, and Facebook channels.

Latest Articles