What is an Algorithm?

Learn about the different characteristics that make an algorithm effective.

An algorithm is an explicit, precise, unambiguous, mechanically executable sequence of elementary instructions, usually intended to accomplish a specific purpose. For example, here is an algorithm for singing that annoying song “99 Bottles of Beer on the Wall” for arbitrary values of the starting number of beer bottles:

Algorithm


BottlesofBeer(n)    For in down to 1Sing “i bottles of beer on the wall, i bottles of beer,Sing “Take one down, pass it around, i1 bottles of beer on the wall.Sing “No bottles of beer on the wall, no bottles of beer,Sing “Go to the store, buy some more, n bottles of beer on the wall.\underline{Bottles of Beer(n)} \\ \space\space\space\space For\space i ←n\space down\space to\space 1\\ \hspace{1cm} Sing\space “i\space bottles\space of\space beer\space on\space the\space wall,\space i\space bottles\space of\space beer,” \\ \hspace{1cm} Sing\space “Take\space one\space down,\space pass\space it\space around,\space i − 1\space bottles\space of\space beer\space on\space the\space wall.” \\ \hspace{0.35cm} Sing\space “No\space bottles\space of\space beer\space on\space the\space wall,\space no\space bottles\space of\space beer,” \\ \hspace{0.35cm} Sing\space “Go\space to\space the\space store,\space buy\space ...