What Is a Computer Algorithm?
1. Algorithm
1.1. Origin of the Algorithm
- The term algorithm comes from the name of the 9th-century Persian mathematician Muhammad ibn Musa Al-Khwarizmi(Muhammadibn Musa Al-Khwarizm).
- He wrote one of the earliest Persian mathematics books and systematically organized arithmetic operations such as addition, subtraction, multiplication, and division based on Arabic numerals introduced from India.
- As his name was rendered in Latin as Algorismus, the word algorithm, meaning a method or procedure for calculation, was created.
Statue of Muhammad ibn Musa Al-Khwarizmi in Urgench, Uzbekistan - [Source] majalla.com
1.2. What Is an Algorithm?
- An algorithm means a defined procedure and method for solving a problem.
- It can be compared to a cooking recipe, but an algorithm differs in that every process must be logically and technically defined with clarity.
1.3. Computer Algorithms
- A computer algorithm is a step-by-step procedure composed of combinations of basic instructions so that a computer can solve a problem.
- In other words, a computer algorithm converts complex problems that humans understand into an ordered sequence of simple operations that a computer can execute.
2. Algorithm Programming
2.1. Euclidean Algorithm
- The Euclidean algorithm is a method for finding the Greatest Common Divisor (GCD) of two integers.
- The greatest common divisor means the largest positive integer that can divide both numbers.
- This algorithm was recorded around 300 BCE by the Greek mathematician Euclid in his work Elements, and it is one of the oldest algorithms in human history.
2.2. Mathematical Principle
- The Euclidean algorithm has the following iterative structure.
- Divide the larger of the two numbers by the smaller number.
- If a remainder exists, divide the smaller number by that remainder again.
- Repeat this process.
- Stop the operation when the remainder becomes 0.
- The last remaining value becomes the greatest common divisor.
The formula for the Euclidean algorithm is shown below.
gcd(p, q) == gcd(q, p mod q)
Here, p mod q means the remainder when p is divided by q, and the principle is that the greatest common divisor of two numbers is the same as the greatest common divisor of the smaller number and the remainder.
2.3. Programming
#include <stdio.h>
int gcd(int p, int q) {
if (q == 0) {
return p;
}
return gcd(q, p % q);
}
int main(void) {
int p = 48, q = 18;
printf("The Greatest Common Divisor of %d and %d is %d\n", p, q, gcd(p, q));
return 0;
}
2.4. Impact of Algorithms
- The Euclidean algorithm is a method for finding the greatest common divisor through a simple procedure, but it is a representative example showing that problems can be solved efficiently through repeated rules.
- This characteristic clearly demonstrates the core principle of algorithms: efficient problem solving through the repetition of simple rules.
- This principle goes beyond a simple mathematical technique and is applied across computer science and cryptography, becoming a foundation for solving various problems efficiently.
- Algorithmic thinking is also used in everyday life, leading to a way of finding the optimal choice step by step while saving time and resources.
* An algorithm is a clear procedure for solving a problem, and a computer algorithm expresses that procedure in a form that a computer can execute. The Euclidean algorithm is a representative example of this concept, showing that efficient solutions are possible through repeated rules and serving as an important foundation for computer science and many other fields.