Algorithms


Algorithms

Definition: An algorithm is a concrete way (think a concrete recipe) to implement a function, i.e, to link a given input to a desired output.

Remark: You may have different algorithms implementing the same function. Some may be better than other in terms of the the output precision, execution speed, easiness of implementation, readability, etc...

In programming, you have essentially two main tools to implement an algorithms:

  • branching mechanisms, which constitute the logical brain of the algorithm
  • looping mechanisms, which constitute the algorithm muscles

Branching mechanisms (Brain)

Implementing a simple choice depending on a logical condition


In [ ]:


In [ ]:

Implementing a cascading series of options


In [ ]:

Looping mechanisms (Muscles)

Looping over the integers


In [ ]:


In [ ]:

Looping over string letters


In [ ]:


In [ ]:

Looping over lists


In [ ]:


In [ ]:


In [ ]:

Conditinal looping


In [ ]:


In [ ]:


In [ ]:


In [ ]: