What is an algorithm?

Asked

Viewed 684 times

16

I would like to know what algorithms are. I program in C, study C++ and Python. In all the online courses I’ve taken, I’ve heard of such an algorithm, but I don’t know what it is.

2 answers

19


An algorithm is nothing more than a recipe (like movie script, cake recipe) that shows step by step the procedures necessary for solving a task. He doesn’t answer the question what to do?, but yes how to do. It is a finite and defined sequence of instructions that must be followed to solve a problem or perform a task.

Switching

What you do in C, C++ and Python (Languages you know) and in any other language is to implement an algorithm, even when it is only one hello world, one for printing 0 to 10.

Example of a lamp exchange algorithm:

 Início
   Verifica se o interruptor está desligado;
   Procura uma lâmpada nova;
   Pega uma escada;
   Leva a escada até o local;
   Posiciona a escada;
   Sobe os degraus;
   Para na altura apropriada;
   Retira a lâmpada queimada;
   Coloca a lâmpada nova;
   Desce da escada;
   Aciona o interruptor;
     Se a lâmpada não acender, então:
         Retira a lâmpada queimada;
         Coloca outra lâmpada nova
     Senão
         Tarefa terminada;
   Joga a lâmpada queimada no lixo; 
  Guarda a escada;
 Fim

Flowchart of an algorithm:

inserir a descrição da imagem aqui

Classifications of Algorithms by Implementations:

Recursive or iterative - a recursive algorithm has the characteristic of invoking itself repeatedly until a certain condition is satisfied and it is terminated.

Logical - an algorithm can be seen as a controlled logical deduction.

Serial or parallel - algorithms are generally assumed to be executed by instructing to instruction individually, such as an execution list, which constitutes a serial algorithm.

Deterministic or non-deterministic - deterministic algorithms solve the problem with an exact decision at each step while non-deterministic algorithms solve the problem by deducing the best steps through estimates in the form of heuristics.

Exact or approximate - while some algorithms find an exact answer, approximation algorithms look for an answer close to the true solution, either through deterministic or random strategy.

Classification of Algorithms by paradigm:

Division and conquest - division and conquest algorithms repeatedly reduce the problem into sub-problems, usually recursively, until the sub-problem is small enough to be solved.

Dynamic programming - dynamic programming can be used to avoid the previously solved solution re-calculation.

Greedy algorithm - a greedy algorithm is similar to dynamic programming, but differs in that the solutions of the sub-problems do not need to be known at every step, a greedy choice can be made at every moment with what hitherto seems to be most suitable.

Linear programming - Solving a problem through linear programming involves maximizing / minimizing the inputs of a set of linear inequalities.

Downsizing - reduction solves the problem by transforming it into another problem. It is also called transformation and conquest.

Search and enumeration - various problems can be modeled through graphs. A graph scanning algorithm can be used to walk through the structure and return useful information for solving the problem.

Heuristic and probabilistic paradigm - probabilistic algorithms make random choices. Genetic algorithms try to find the solution through cycles of evolutionary mutations between generations of steps, tending to the exact solution of the problem.

Sources:

What is an algorithm - Tecmundo

Algorithm - Wikipedia

  • 2

    It was huge. But I liked it. Let me see if I understand: the algorithm is what shows the steps for solving a task. For example, when creating a while loop to count from 1 to 10, I made an algorithm that shows all the steps to make the program go up to 10 and stop.

  • you have implemented an algorithm that prints from 0 to 10 and finishes.

  • Do you know English? it is a pseudo-language used to teach algorithm structuring.

  • The same way for Hello World, right?

  • Yes. I’ve heard of Portugol. I’ve seen it on Wikipedia.

  • My opinion: It is better to learn how to create algorithms directly in the language C why you learn to create algorithms and at the same time a real programming language.

Show 1 more comment

2

It is a finite sequence of rules, reasoning or operations that, applied to a finite number of data, allows solving similar classes of problems. Practically summing up is like a cake recipe, will have to perform step by step to solve a problem. Usually at the beginning of computer studies, people choose to study algorithms with the English language in Visualg. (Because the syntax is in Portuguese and seems to be easier)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.