Search⌘ K
AI Features

What is an Algorithm?

Learn to define an algorithm as a precise sequence of steps designed to solve specific problems. Understand its historical origins from al-Khwarizmi's work to modern computation, and see practical examples that clarify algorithm implementation and design principles.

Introduction to algorithm

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 ...