The Benefits of Learning Algorithms
Often, algorithms are considered only when someone is looking for a new job. This tight perception of algorithm usage is far from what algorithms allow us to achieve.
Join the DZone community and get the full member experience.Join For Free
Algorithms are everywhere! Algorithms are involved in each aspect of computer science. They're also used in a wide range of fields such as recommendations, social media, medicine, psychology, and transportation... and the list is longer still!
Anything you do can be broken down into small steps and that is the essence of an algorithm. Imagine that you wake up the morning to go to work and you can’t remember where your car keys are. How would you find them? One approach might be to apply an algorithm, which is a step-by-step logical procedure. First, you look for places where you usually put them. You try to remember the last time you used them. You check the first room you went to when you got home. Sooner or later, by the flow of steps, you eventually find the car keys. An algorithm is a sequence of instructions that ensure a certain task completion. We, as humans, apply algorithms in order to take actions in every aspect of our lives.
So, algorithm knowledge can be an asset in improving your life or even others’ lives! You can turn something that takes a lot of time to decide on into an algorithm that assists you in the decision-making process. You can create an algorithm in order to prioritize your tasks instead of doing it with a simple to-do list. You can make an algorithm in order to predict the best time to visit a city. You can make an algorithm in order to get suggestions on what films to watch according to your preferences and historical data. There is no limit to what you imagine and can make real by applying algorithms!
Now, I think it’s time to start talking about how to gain those set of skills in order to make a difference with algorithms! First, let’s go for the characteristics of an algorithm.
What are the characteristics of an algorithm?
- It should be finite. If your algorithm never stops trying to solve the problem it was designed to solve, then it is useless.
- It should have well-defined instructions.Each step of the algorithm has to be precisely defined; the instructions should be unambiguously specified for each case.
- It should be effective.The algorithm should solve the problem it was designed to solve. And it should be possible to demonstrate that the algorithm converges with just a paper and pencil.
What Are the Steps to Learn Algorithm Coding?
- Develop your programming logic. Here some ways to improve it.
- Pick up a programming language you are comfortable in (if you don’t have any, I suggest learning Python — it’s easy and simple).
- Learn data structures. Start with the basic ones: strings, vectors, lists, arrays, maps. Then, queue and stack. Finish with the more advanced ones: trees, graphs, and tries.
- Practice coding data structures. Here is a good resource.
- Learn simple algorithms first and then move to the most common algorithms. Make sure you understand every step and don’t be frustrated if you're slow. Remember: It does not matter how slowly you go as long as you don’t stop! You can look for videos because they make it easier to assimilate.
- Start tackling problems (for example, in Hackerrank, there are funny and challenging algorithms). You must have a strategy of resolving problems, I’d suggest following the method proposed by Gayle Laakmann McDowell.
Finally, through my own modest experience in problem-solving, here is my advice:
- Ask questions. "Why" and "what" are really important in order to understand the basics of anything! When you question the choice, you will better memorize the answer and you will dig deeper into the source of the information.
- To stay motivated and keep the learning curve up, create a simple daily useful algorithm after getting the basics. Accomplishment fuels your energy.
- Try to solve the problem manually by yourself first. Take a paper and start writing steps. Especially take your time and don’t move on to the solution fast.
- Even if you figure out the solution, don’t tell yourself, "It’s ok now, no need to implement it, I know how it works." It’s a big trick there because you never know what you missed if you don’t try it and test it with corner cases.
- Be patient. If you begin to feel frustrated about a problem, leave it and go do something that is not so stressful. Then, come back.
I hope this helps you to leverage the power of your brain by discovering its super capabilities to execute algorithms and learn how to translate them into code!
Remember how was Rome built? Not in a day, right? By each small step in learning algorithms, you are growing your potential to contribute to making life better in this world!
Topcoder: An explanation of data structures and algorithms.
ideserve: Contains a visual explanation of some algorithm problems.
Tushar Roy: An explanation of some advanced algorithms.
Published at DZone with permission of Sarah Mestiri. See the original article here.
Opinions expressed by DZone contributors are their own.