Algorithmic Thinking has recently become a buzzword among programmers. It is a method for solving problems based on a clear definition of steps: logically and repeatedly. This could help us understand several problem-solving strategies.
In programming, two skills are critical to solving a coding problem: 1) Identifying and designing an efficient solution approach and 2) Converting the solution approach into a correct code. Some programmers face challenges developing the first skill, which requires algorithmic thinking. On another side, sometimes interviewers offering problems during interviews claim that they are more interested in how an interviewee approaches a problem than the implementation of the solution. Showing expertise in algorithmic thinking and applying problem-solving strategies can be an attractive way to impress a potential employer.
The critical question is: How do we develop algorithmic thinking independently from learning programming? There are several ways of it! Let's explore.
Solving algorithmic puzzles is a productive and enjoyable way to develop algorithmic thinking. This could help us think about a coding problem on a more abstract level. For example, we can learn several problem-solving strategies using puzzles:
Here are some more examples of such types of puzzles:
Puzzle based on the properties of numbers theory
Puzzle based on properties of graph
Puzzle based on incremental approach
Puzzle based on graph-based transformation
Puzzle based on dynamic programming
Puzzle based on incremental approach
Puzzle based on idea of backtracking
Puzzle based on iterative elimination
Puzzle based on properties of the graph
Puzzle based on idea of elimination
Puzzle based on idea of transformation
Puzzle based on mathematical counting
Here are some essential ideas related to solving algorithmic puzzles:
The solution to every problem has to go through well-defined steps, and practicing these steps helps us save time and understand patterns among several coding problems.
Step 1: Understanding the problem statement
We need to understand the problem by drawing a clear visualization. We should ask these critical questions: Do we know every word used within the problem? What data or information are provided as input? What data or results are requested as an output?
In addition to this, we need to understand computational and non-computational details relevant to the problem like data structures, specific constraints given on input, distribution of the input, etc.
Step 2: Selecting concepts and solution strategies based on experience
Based on problem description, we need to make predictions regarding concepts necessary to solve the problem. We should think: Are we going to use all information available in the problem? Is it possible to eliminate unnecessary information? Have we solved any similar problems in the past? If yes, then take advantage of that experience. Identifying approaches or concepts or already known algorithms for similar problems can help us save a lot of time.
Step 3: Formulation of a solution strategy and pseudocode
We should explore a hand-written way to solve problem by going through several examples and developing general step-by-step strategy. To do this, we need to carefully think about each step and observe what actions are common to every example. Two types of thinking are important at this stage:
We need to visualize solution steps on the paper by describing operations to transform the given input into the desired output. After this, we can move forward to write step-by-step solutions in simple English and Transform them into pseudocode or flowchart.
Step 4: Correct Programming Implementation
Now we can move forward to transform the pseudocode into a working code using our favorite programming languages like C++, Java, Python, etc. During this process, we need to select programming elements for efficient code implementation and simplify data handling: Solution function, helper functions, loop initialization and termination, base cases of recursive code, scope and initialization of local variables, global variables, memory allocation, and deallocation, pre-processing, pointers manipulations, etc. Note: Please take care of the correct coding style :)
Step 5: Verifying correctness and optimizing further
Now, we need to test the programming implementation for bugs, analyze time and space complexity, and think to optimize solution further. These ideas can work best at this stage:
Here are some popular coding questions to practice the steps of problem-solving. These questions can be solved using four or more approaches.
In our surroundings, many applications are using efficient problem-solving strategies to deliver the best user experience and performance. Understanding the idea behind such a strategy is a defining step in developing algorithmic thinking. For example:
Enjoy learning, Enjoy thinking!
Subscribe to get weekly content on data structure and algorithms, machine learning, system design and oops.