What is an algorithm?

15

I'd like to know what algorithms are. I program in C, study C ++ and Python. In all the online courses I've done, I've heard of such an algorithm, but I do not know what it is.

    
asked by anonymous 10.05.2015 / 12:08

2 answers

18

An algorithm is nothing more than a recipe (such as a movie script, cake recipe) that shows you the step-by-step procedures for solving a task. It does not answer the question what to do , but rather how to do . It is a logical, finite, and defined sequence of instructions that must be followed to solve a problem or perform a task.

  

Changing kids

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 a hello world , a for that prints from 0 to 10 .

Example of algorithm for changing a lamp:

 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:

  

Algorithmclassificationsbyimplementations:

Recursiveoriterative-Arecursivealgorithmhasthecharacteristicofinvokingitselfrepeatedlyuntilacertainconditionissatisfiedanditisterminated.

Logical-analgorithmcanbeseenasacontrolledlogicaldeduction.

Serialorparallel-Algorithmsareusuallyassumedtobeexecutedbythestatementstatementindividually,asalistexecution,whichconstitutesaserialalgorithm.

Deterministicornondeterministic-deterministicalgorithmssolvetheproblemwithanexactdecisionateachstepwhilenon-deterministicalgorithmssolvetheproblembydeducingthebeststepsthroughestimationsintheformofheuristics./p>

Exactorapproximate-whilesomealgorithmsfindanexactanswer,approximationalgorithmslookforaresponseclosetothetruesolution,eitherthroughdeterministicorrandomstrategy.

  

AlgorithmClassificationbyParadigm:

DivideandConquer-Algorithmsofdivisionandconquestrepeatedlyreducetheprobleminsub-problems,usuallyrecursively,untilthesub-problemissmallenoughtoberesolved.>

Dynamicprogramming-Dynamicprogrammingcanbeusedtoavoidrecalculationofpreviouslysolvedsolutions.

GreedyAlgorithm-Agreedyalgorithmissimilartodynamicprogramming,butdiffersinthatsolutionsofsub-problemsneednotbeknownateverystep,agreedychoicecanbemadeeveryatwhattimeitseemstobemoreappropriate.

LinearProgramming-Solvingaproblemthroughlinearprogramminginvolvesmaximizing/minimizingtheinputsofasetoflinearinequalities.

Reduction-Reductionsolvestheproblembyturningitintoanotherproblem.Itisalsocalledtransformationandconquest.

Searchandenumeration-variousproblemscanbemodeledthroughgraphs.Agraphexplorationalgorithmcanbeusedtowalkthroughthestructureandreturnusefulinformationtosolvetheproblem.

HeuristicandProbabilisticParadigm-Probabilisticalgorithmsmakechoicesatrandom.Geneticalgorithmstrytofindthesolutionthroughcyclesofevolutionarymutationsbetweengenerationsofsteps,tendingtowardstheexactsolutionoftheproblem.

Sources:

What is an algorithm - Tecmundo

Algorithm - Wikipedia

    
10.05.2015 / 13:55
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 summarizing is like a cake recipe, you will have to perform step by step to solve a problem. Generally at the beginning of the studies in computer the personnel opts to study algorithms with the language Portugol in VisualG. (Because the syntax is in Portuguese and seems to be easier)

    
19.10.2017 / 19:44