HomeDefinitionsAlgorithms: Definition and Examples

Algorithms: Definition and Examples

What Are Algorithms, and Why Are Th...
What Are Algorithms, and Why Are They Important?

Although sometimes we don’t realize it, we use algorithms in our daily lives. From computers, smartphones to space science, algorithm is an essential tool or combine of tools nowadays.

What is an algorithm?

The algorithm is simply a “ recipe ” for performing a task or solving a problem. Computer science uses this tool a lot, in particular in the field of programming.

A very important aspect of algorithms is efficiency. For many problems, it is quite easy to find a procedure that ends up giving the correct answer, but the real difficulty lies in finding an algorithm that finds the answer efficiently.

If the operations of an algorithm run one after the other, it is a sequential algorithm, if they run in parallel, it is a parallel algorithm. If the algorithm exploits tasks running on a network of processors, we speak of a distributed algorithm.

Algorithms Definition historical chart-min

The word “algorithm” comes from the name of the mathematician Al Khuwarizmi (Latinized in the Middle Ages as Algoritmi), who in the 9th century wrote the first systematic work on the solution of linear and quadratic equations.

Example Algorithm

Alice and Charles play a game: Alice thinks of a number between 1 and 100 and Charles tries to guess it. Charles can ask for a particular number, and Alice responds if that number is the one she’s thinking or if the number is larger or smaller than she thinks.

Charles can simply ask 1, then 2, then 3, and so on until Alice answers that he is right. This algorithm is very simple and always works. But let’s compare it to this other algorithm: Charles starts by proposing the number 50. If he succeeds, the game is over.

On the other hand, if Alice answers that the number is higher, Charles will continue and propose 75. Or, if Alice answers that the number is lower, the next number that Charles suggests is 25. Charles repeats this strategy several times, in each time halving the range of possible numbers, until he unequivocally reaches the number Alice chose.

This second algorithm also finds the answer each time, but is much more efficient. Thus, with the first algorithm, Charles may have to ask up to 100 questions whereas with the second algorithm, whatever number Alice chooses, Charles will ask a maximum of 6 questions. This idea of “halving” is very common in the field of algorithms.

To sum up, algorithmics includes the study of problem solving by implementing sequences of elementary operations according to a defined process leading to a solution.

Algorithm structures

The concepts implemented in algorithms, for example according to N. Wirth’s approach for the most widespread languages (Pascal, C, etc.), are few in number, they belong to two classes:

  • control structures
  • sequences
  • conditional
  • loops
  • data structures
  • constants
  • variables
  • tables
  • recursive structures (lists, trees, graphs)

This division is sometimes difficult to perceive for certain languages (Lisp, Prolog, etc.) more based on the notion of recursion where certain control structures are implicit (and therefore seem to disappear).

Some indications on the efficiency of the algorithms

Often, the efficiency of an algorithm is only known asymptotically, i.e. for large values of the parameter n. When this parameter is small enough, a higher complexity algorithm may in practice be more efficient.

Thus, to sort an array of 30 rows (this is a small parameter), it is useless to use an advanced algorithm such as Quick Sort (one of the most efficient sorting algorithms on average): most trivial sorting algorithm will be efficient enough.

Between two algorithms whose complexity is identical, we will seek to use the one whose memory occupation is the lowest.

Algorithmic complexity analysis can also be used to assess the memory usage of an algorithm. Finally, the choice of one algorithm over another must be made based on the data that is expected to be provided as input.

Thus, the Quicksort (or rapid sort), when we choose the first element as pivot, behaves in a disastrous way if we apply it to an already sorted list of values. It is therefore not wise to use it if it is expected that the program will receive lists that are already almost sorted as input.

Another parameter to consider is the locality of the algorithm. For example, for a virtual memory system which has little memory (compared to the number of data to be processed), Quick Sort will normally be more efficient than Heap Sort because the former only passes once on each element of memory while the second accesses the memory in a discontinuous way (which increases the risk of swapping).

Finally, there are some algorithms whose complexity is said to be damped.

This means that, for some executions of the algorithm (edge cases), the complexity of the algorithm will be much higher than the average case. Of course, the notion of damped complexity is only used in cases where this reaction is very marginal.

What exactly is an algorithm? Algorithms explained

Mehmet S. Kaya
Mehmet S. Kayahttps://teknonel.com
Mehmet is one of the administrator of Teknonel. As a software developer, he loves to share his knowledge in related topics. He is highly familiar with the editorial process from the inception of an article idea, through the iterative process, publishing, and performance analysis as well as product reviews.


Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!

Follow us on Social Media!


Related Articles

Buffer memory: Definition and Working Mechanism

Buffer memory is a memory or part of memory allowing the temporary storage of data between two electronic bodies having different characteristics.If something is...

Reverse engineering: Definition, Uses and Importance

Reverse engineering is the analysis of a system that is aimed at researching its design principles.Although reverse engineering is most often used for the...

Ping: Definition, Importance in Games

Acronym for Packet Internet Groper, the Ping is a component of the Internet connection protocol that makes it possible to verify the connections established...

Magnetic field: Definition, History and Importance

The term magnetic field designates a region of space subjected to the action of a force coming from a magnet. It also characterizes the...

Explore More Articles

LG ultra ince araç hoparlörleri tasarlardı-min

LG wants to revolutionize the speakers used in cars

The Slim Actuator Sound Solution designed by LG is quite light unlike conventional speakers. While traditional speakers are large and heavy due to components...

Why do we always see the same side of the Moon?

We always see the same side of the Moon and that is because our natural satellite takes the same time to go around on...
170.000 PET şişeden yapılan yüzer dalga enerjili deniz suyu tuzdan arındırma ekipmanı görücüye çıktı

New Desalination device made from 170,000 recycled plastic bottles

This extraordinary desalination device is powered by mechanical power from waves as it floats in the ocean, producing up to 13,000 gallons (53,000 liters)...
Samsung Galaxy S23 is rumored to support low-orbit satellites

Samsung Galaxy S23 is rumored to support low-orbit satellites

With Apple's iPhone 14 and Huawei's Mate 50 flagship series equipped with satellite emergency services.Now more and more mobile phone manufacturers are also planning...