Photo by Markus Spiske on Unsplash

Over the last few months, I’ve been working on writing an article about artificial intelligence and eye care.

To begin this journey is learning about this topic. We need to understand what are algorithms.

An algorithm is what computers use to solve problems, taking input and provide the desired output.

Here is an example. We have a list of names that we need to sort alphabetically. We could do this by hand, but let’s leverage the power of computing to solve this problem for us instead. After all, a computer can perform tasks tirelessly and without error, if they are programming correctly of course.

Also, imagine if we had hundreds or thousands of patients, then the tasks becomes very long and tedious.

We can construct a simple algorithm to loop through the list of names and compare this to the name first on the list. If the name falls before the first-most name alphabetically, then this will take the top spot. We then repeat this for the entire list of names.

I’ve coded this example in C. Here it is below.

We have some interesting functions:

  • - this compares strings and if the value is above 0, then is 'greater' than . In other words, goes after in the alphabet.
  • - when the above condition is met, this copies the value of to . In our case, the later-in-the-alphabet name is copied to . The name is replaced by the earlier-in-the-alphabet name. The name assigned to then takes its place.

We can see that two loops are implemented to make this happen. This means if the list of names increases by , then the time for this algorithm to be executed will increase by a square factor, . This means that this is not the most efficient algorithm, but it works and I'm happy with that.

We compile the code and then run it. We can see the output below.

Here we are. I hope you enjoyed reading this.

I am an Optometrist who is intersted in technology.