Problem solving is a huge part of computer science. In fact computer programming is basically the process of solving a problem with code. These problems are solved by means of algorithms. An algorithm is a step by step instruction to solve a problem.
We implement algorithms in many aspects of our lives even without knowing it. For example if I wanted to make a cup of tea, I would take the following steps.
What I’ve written above is what is commonly known as pseudo code. It’s a good practice to write pseudo code before writing an algorithm just to give you an idea of the steps you would take to solve the problem at hand.
Algorithms are built on fundamental concepts. These act like building blocks for writing algorithms successfully. We’ll go through these fundamental concepts for in this article.
Functions are like verbs or actions that tell a computer what to do. Functions are usually written for actions that would need to be repeated several times. The fundamental idea of functions is to wrap all the steps involved in carrying out a particular action in one block of code.
For example, we have several actions in our steps like walk boil grab fill etc. For such actions it would be ideal to write a function other than define them everywhere they need to be carried out.
When writing functions, it’s always good to keep the following in mind
I wrote an article about functions in JavaScript. Feel free to check it out here
Conditions are like branches that tell a computer which path to take in certain situations.
Conditions are written with the if keyword followed by the condition to be met. Multiple conditions can be nested together using the else if keyword. Its also possible to set a default outcome if none of the conditions are met using the else keyword.
Going back to our tea making algorithm, if we wanted to make sure that the water boils to 100 degrees, we could use a condition to check whether the water is 100 degrees then stop boiling.
#fundamentals #algorithms #programming #beginner #learning-to-code #algorithms