How to Actually Solve a Problem
Approach to Problem Solving for Programmers
Programmers are problem solvers. Problem solving is the most important part of development and the difficult part. You have to build your problem solving skills by practice.
In order to solve a difficult problem, you need a plan to approach it and tackle it. I’ll share some steps and methods that’ll help you to reduce the complexity of hard problems and solve it effectively.
1. Understand the Problem
Understanding the problem is the most crucial step in problem solving. You should deeply understand a problem in order to form a solution for it. Understanding the problem includes having a clear idea about problem statement, constraints etc…
Solving the right problem is obviously the most important part, so you have to spend time on going through the problem. You should be 100% sure that you understand the problem before even attempting a solution.
You can try out some examples to make sure you understood it correctly and you can ask someone or look for details to clarify if the problem seems confusing to you.
2. Come Up with Ideas
You should come up with all the ideas of possible solutions. Write down all the ideas that comes to mind and expand the ideas and write in more detail about each idea. It will help you to know whether an idea is fit for the problem or it might give you other ways to think about it.
Formulating ideas can be challenging. You will be able to come up with obvious ideas, but they may be slow. You have to keep going and formulate more and more ideas. It will be a great exercise to open up your creativity and improve your problem solving skills. You will get ideas and approaches from different angles, which will help you in similar problems in the future.
You can get ideas by observing patterning, splitting problem into smaller sub problems etc… You can also try something random, even if it is wrong, it may give you leads towards a possible solution.
3. Choose and Design a Solution
Now that you have a lot of ideas, you have to choose a possible efficient solution and design it. Use paper and formulate an algorithm for your solution. Make sure your algorithm works perfectly . Do some examples on paper with your algorithm and make it free from any possible bugs.
Try a lot of corner cases and tweak your algorithm if needed to include those corner cases. Do not move on to the coding part before making a good algorithm.
Always try to optimise and make a highly efficient algorithm. You should try your best and give it some time. Sometimes it might take you some more time to come up with a good algorithm. Try again and again. Also if you have been stuck for a long time, take pause for some time and engage in some other activities and after that if you come back to the problem, you might be able to solve it faster.
4. Implement Your Solution
Now it’s time to convert your algorithm to actual code.Translate your designed solution to code by splitting it in to small chunks so that it will be easier to implement.
Break your code into sub routines and always make sure everything works after implementing each sub routine. Always try to implement a sub routine and compile it and test it to avoid any possible errors before moving on to next sub routine.
If you have syntax errors then analyse the log and fix errors on corresponding lines pointed out by the compiler. Logical errors can be fixed by tracing through the program line by line with an example input to understand where the code fails and why it fails. If the output doesn’t match with your expected output, use multiple print statements after each steps to understand how output is generated.
5. Check, Review and Improve
This is the most overlooked step in development and problem solving. But it is the most crucial step to make your code efficient and bug free. You should test your solution with a ton of inputs, which include every corner cases etc… Your solution should be able to handle all types of input. You have to think critically about your code and try to patch up every holes that can be exploited.
Review your code and think of any improvements that can be done to it to increase it’s efficiency even one bit. You should also consider readability of the code. Always include comments in your code, even if you understand your code doesn’t mean another person will be able to understand it.
Always check for ways to improve your code and make it efficient. If you can save a little bit more of space or time, it can go a long way on bigger inputs.
Don’t forget : Problem solving is hard, it is a creative process. You should improve your problem solving skills by practise. It doesn’t come in one day or a week. It takes consistent effort to improve your problem solving skills.
Don’t get frustrated if another person improves faster than you do. Everyone has their own pace and learning curve. Everyone is different, and each have different strengths and weaknesses. You can always improve. On a long run it is always about consistency and discipline. Also you will learn a lot from your mistakes.
If you find this guide helpful, don’t forget to share it to your friends who are interested in content like this. Do you have your own strategy to tackle hard problems ? Share it in the comments ! Thank you for reading