• What are Algorithms and How Can We Lear...

What are Algorithms and How Can We Learn to Build Them

Problems have been around for as long as humans have been able to think (that's a very long amount of time isn't it?). As problems arose, people tried to solve them. Let's try and use a very simple problem to get us started: I want to cook an egg. Now how can I go about cooking an egg?

Find A-level Computer Science Tutors

The first step would be to break it into a smaller set of sub-problems to scope out the problem. Let's list some questions we would need to answer before we can solve this problem:

  1. Do I have an egg?
  2. What do I need to cook an egg?
  3. What utensils do I have?
  4. How should the egg be cooked?
  5. Does it need to be boiled?
  6. If I don't have an egg, where can I get one?

As it stands right now, these are all valid questions. However, when we make algorithms, we can make simplifying assumptions. These assumptions allow us to focus on the problem at hand, instead of writing an entire story. 

In this example, we can make the following simplifying assumptions about the problem to make it easier to solve:

  1. We have a white egg
  2. We need to fry the egg
  3. I have a spatula
  4. I have a frying pan
  5. I have salt and pepper
  6. I have a stove to cook it on

Given that our problem is much more simplified at this point, we can try and come up with an algorithm.

What is an algorithm?

You can think of an algorithm as step-by-step instructions to solve a problem. It's like a recipe -  a series of specific and precise actions that, when followed correctly, yield a desired outcome. 

Given that we know about the word algorithm now, we can now try and make an algorithm for cooking an egg

The Algorithm

  1. Take a bowl
  2. Break an egg using a spoon and empty the contents into the bowl
  3. Add some salt
  4. Use a fork to whisk your egg until it's mixed well
  5. Put your frying pan on the stove
  6. Turn on the stove
  7. Add some oil to the pan
  8. Let the oil heat
  9. Once it is heated up, add the egg mixture from the bowl
  10. Flip the egg
  11. Cook the other side
  12. Remove from the pan into a plate once done

Analysis

Each algorithm can be analysed in terms of efficiency, precision, reusability and correctness. Let's see what each of these means:

  • Precision: Algorithms are defined with precision, leaving no room for ambiguity or interpretation. Each step must be explicitly outlined, ensuring clarity and accuracy in execution
  • Efficiency: An efficient algorithm accomplishes its task using the fewest possible steps, minimizing resource consumption such as time, memory, or energy. Efficiency is a crucial consideration in algorithm design, particularly when dealing with large datasets or time-sensitive applications.
  • Reusability: Well-designed algorithms are modular and reusable, meaning they can be applied to similar problems or integrated into larger systems with minimal modifications. This promotes code simplicity, maintainability, and scalability.

Find a Computer Science Tutor Near Me

  • Correctness: Above all, algorithms must produce correct results when executed under specified conditions. Rigorous testing and validation are essential to ensure that algorithms behave as intended across various scenarios and inputs.
Did you like this article? Share it now
Muhammad Jazlan
I am a computer scientist and researcher at one of Asia's top Computer Science universities, soon to start a PhD at a very prestigious US institution.Contact
Contact
Use our Smart Finder