Other Parts of This Series:
- Part 6: Let’s Feel Programming Fundamentals - Part 6 (Data Structure)
- Part 8: Let’s Feel Programming Fundamentals - Part 8 (Threads, Async-await, Concurrency, Parallel)

Algorithm (Photo Credit: knowitallninja)
In this part, we will try to understand what a algorithm is. Also see different types of algorithm based on the solution procedure. Please note: we will not dive deep for the sake of simplicity. If you feel really interested, you can explore each of them in details. And may be I will write each of the topic in details in future insha Allah.
Story
I have a close elder brother-like friend named A. S. M. Jehan. It is high time for him to marriage. So for him, getting married as soon as possible is a problem. We need a solution to solve the problem. As we are programmers, we plan some steps that lead us to the solution. They are:
- First we need to hire a matchmaker.
- Then the matchmaker presents us with different girls photo, and we need to choose girls for initial screening.
- After that we need to start meeting the girls face-to-face and talk to their family.
- Then, if all criteria are being fulfilled, then we should go for the marriage arrangement.
- Finally, arrange the marriage ceremony, and done.
- Then BOOM!!!
Algorithm
In simple words, an algorithm is a set of instructions for solving a problem or accomplishing a task. That means an algorithm is some efficiently predefined ordered steps/instructions that can be followed to perform a task, calculate some results, or solve a problem. By following an algorithm that is best matched to solve a problem, the solution is fast, efficient, convenient, and easy.
An example of defining steps of an algorithm to solve a problem can be like the story above. Here we define the steps from 1 to 6 to solve the marriage problem of Jehan, bro. By following the steps, we can solve the problem.
Based on the solution procedure algorithm can be the 10 types generally. They are:
- Brute force algorithm: A Brute Force Algorithm is the straightforward approach to a problem i.e., technically it is just like iterating every possibility available to solve that problem. It’s also called constructive algorithm because we construct this without following the other algorithms, data structures type and only focus on the problem itself.
- Simple recursive algorithm: Recursion is the way for breaking a problem into subproblems and calling its own self function again and again. An algorithm based on the recursion is called a recursive algorithm. Some examples of this type are: Fibonacci series, Factorial of a number, DFS for graphs, Tower of Hanoi etc.
- Backtracking algorithm: It is an algorithmic technique for solving problems recursively by trying to build a solution incrementally, and after a moment it back to the point and try with other items/possibilities. As it can back and forward with other items that is why it is called backtracking algorithms because it tracks the back also. Examples of this type are: M-coloring problems, Rat in maze, N-queens problems, Hamiltonian cycle etc.
- Divide and conquer algorithm: In Divide and Conquer algorithms, the idea is to solve the problem in two sections, the first section divides the problem into subproblems of the same type. The second section is to solve the smaller problem independently and then add the combined result to produce the final answer to the problem. Examples of this type are: Binary search, merge sort, quick sort, Strassen’s matrix multiplication etc.
- Gready algorithm: A greedy algorithm creates the solution portion by portion. It never considers the choices that had been taken previously. Examples of this type are: Dijkstra shortest path algorithm, Prim’s algorithm, Kruskal algorithm, Huffman coding algorithm etc.
- Dynamic programming algorithm: It is known as recursion with memorization techniques. It solves the subproblems and remembers the result for avoiding calculation again. Examples of this type are: Knapsack problem, Weighted job scheduling, Floyd warshall algorithm, subset problem etc.
- Sorting algorithm: This is the algorithm that is used to sort data based on some condition more formerly ascending or descending. Examples of this type are: bubble sort, selection sort, quick sort, merge sort etc.
- Searching algorithm: Using this type of algorithm data is being searched from a collection of data. Examples of this type are: linear search, binary search, ternary search etc.
- Hashing algorithm: Hashing algorithms work the same as the Searching algorithm but they contain an index with a key ID i.e. a key-value pair. In hashing, we assign a key to specific data.
- Randomized algorithm: This is an algorithm type that makes its decision on the basis of random numbers i.e. it uses random numbers in its logic. Best example of this type of algorithm is quick sort for selecting pivot point. Its also known as probabilistic algorithm.
Insha Allah, in the upcoming blogs we will deep dive each fundamental concepts. Till than, may Allah keep you healthy and happy.