Article 3

Algorithms

The real magic

en 01/08/2021 23:48 Mahmud El Adwi

Do you believe in magic?
What if I told you that there is a set of spells that can do a lot of things super fast and all at once.
Spells that made inanimate objects smarter and more powerful than humans, brought us to space and made the whole world available in our hands with just a click of a button.
These spells are called algorithms.

An algorithm is a set of mathematical, logical, and sequential steps needed to solve a problem.
Al-Khwarizmia in arabic was named after the scholar Abu Jaafar Mohammed bin Musa Al-Khwarizmi, who invented it in the ninth century AD. The common word in Latin and European languages is “algorithm” and originally its meaning was limited to an algorithm of only three combinations:
Sequence which is the order in which instructions occur and are processed.
Selection that determines which path that should be taken to solve the problem depending on some criteria.
Iteration is looping or repeating a set of operations a specific number of times or until some condition occurs.

Mohammed bin Musa Al-Khwarizmi

From recommending movies to filtering news to finding our life partners, algorithms are all around us.

In 2012, the American mathematician Lloyd Shapley was awarded the Nobel Prize in Economics, for finding an algorithm to solve what's known as stable matching problem (SMP)
In mathematics, economics, and computer science, the Gale–Shapley algorithm (also known as the deferred acceptance algorithm or propose-and-reject algorithm) is an algorithm for finding a solution to the stable matching problem, named for David Gale and Lloyd Shapley who had described it as solving both the college admission problem and the stable marriage problem. It takes polynomial time, and the time is linear in the size of the input to the algorithm. It is a truthful mechanism from the point of view of the proposing participants, for whom the solution will always be optimal.

    Lloyd Shapley
    David Gale

How to write an Algorithm

To write an algorithm. You have to follow certain steps. It is not even necessary to understand them. But they must be strictly followed.

  1. Problem Definition

    Defining the problem is the first step in solving the problem. The inputs and outputs are precisely and clearly defined in the form of variables. As a programmer, you must define the concepts of the problem in the form of variables with a specific name and a specific data type, where these data are referred to in the algorithm. Through the name, and the type of data determines the operations that can be performed on the data, there are many types of data, but you can classify the data into two main types, which are numeric data and text data.
    In this step, a table with data is usually created, so that this table contains two main classifications: Input Variables, Output Variables.

  2. Writing an Algorithm

    In this step, the programmer must think about how to solve the problem, and then divide this method into a group of steps, so that each step performs only one operation, and the order of these steps must be carefully taken in consideration, because the computer performs these steps one by one in the order in which it does the programmer, and the programmer may define new variables to help solving the problem, in which case these variables are called Program Variables, and these variables are neither inputs nor outputs.

    Before you start writing the algorithm, you should know that there are two ways to write the algorithm:

    • Pseudo Code

      In this method, the programmer writes the steps to solve the problem (algorithm) in a numbered or unnumbered sequence, and writes each step on a separate line. The programmer may use his language, whether English, Arabic Chinese...etc , to write the sequence of steps.
      One of the most important features of this method is flexibility, as the programmer can write his ideas in the form of steps in the basic language that he uses in his daily life, usually well-written algorithms in this way are easy to convert into codes or computer commands.
      But the main disadvantage of this method is that with the large size of the algorithm it becomes difficult to track and review its steps.

    • Program Flowchart

      In this method, the programmer writes the steps of solving the algorithm using a set of basic geometric shapes so that each shape represents a step of solving the problem, and there is a prevailing and followed standard for the use of these shapes.
      One of the advantages of using this method is that it is direct and simple, in which it is easy to follow the steps of the algorithm, and also the algorithm written in this way can be understood by any programmer, whatever language he speaks.
      One of the most important disadvantages of this method is that it is difficult to convert it into codes if you use programming languages such as C, It is difficult to write complex algorithms in this way.

  3. Tracing the Algorithm

    In this step, we test the algorithm that we have written, by entering data that is known in advance, step by step to measure the validity and efficiency of the algorithm.

  4. Writing Code

    Here, you must first learn any programming language in order to be able to convert the algorithm that you've designed into a program, like JavaScript programming language with the HTML markup language.

The conclusion is that the main goal of learning about algorithms is to change the way we look at things, so that algorithms do not differ much from magic spells, as they, with certain steps, solve many problems that human beings are not capable to solve.

But of course there are some unresolvable problems. In 1936, British mathematician Alan Turing (the godfather of modern computers) proved that there is no algorithm that can solve the halting problem.
The halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running, or continue to run forever.

Also, we can't solve all problems that have a solution.
For example, in 1962 Procter & Gamble company offered a prize of $10,000 (about $80,000 in today's money) to anyone who would solve the following Euclidean:
The contest asked for the shortest tour through 33 cities in the US , with the condition of visiting every city only once.
Although the issue seems simple, it has a huge number of possibilities.
The first city you visit will be one of 33 possibilities, as a second city we have 32 possibilities, as a third we have 31 possibilities and so on. Which leaves us with approxamitally 1037 possibilities. If we turn this problem into an algorithm and run it on the fastest computers of our time. It would take 300 billion years to find the solution. This means 20 times the age of the universe.
This problem is known as Travelling Salesman Problem TPS, and it belongs to the class of combinatorial optimization problems known as NP-complete (Nondeterministic polynomial).

My point of view: Without algorithms, we would not have been able to reach what we have reached as human beings. The door is still open for discovery about these amazing and powerful spells. And you should know, dear reader, that every discovery of a new algorithm is a victory for humanity as a whole.

Leave a comment with your opinion.

Thank you.

Sources
Designed by Mahmud El Adwi