An algorithm is a step-by-step procedure to solve a problem. A good algorithm should be optimized in terms of time and space. Different types of problems require different types of algorithmic-techniques to be solved in the most optimized manner. There are many types of algorithms but the most important and the fundamental algorithms that you must know will be discussed in this article.
Brute Force Algorithm:
This is the most basic and simplest type of algorithm. A Brute Force Algorithm is the straightforward approach to a problem i.e., the first approach that comes to our mind on seeing the problem. More technically it is just like iterating every possibility available to solve that problem.
For Example: If there is a lock of 4-digit PIN. The digits to be chosen from 0-9 then the brute force will be trying all possible combinations one by one like 0001, 0002, 0003, 0004, and so on until we get the right PIN. In the worst case, it will take 10,000 tries to find the right combination.
This type of algorithm is based on recursion. In recursion, a problem is solved by breaking it into subproblems of the same type and calling own self again and again until the problem is solved with the help of a base condition.
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.
Dynamic Programming Algorithms:
This type of algorithm is also known as the memoization technique because in this the idea is to store the previously calculated result to avoid calculating it again and again. In Dynamic Programming, divide the complex problem into smaller overlapping subproblems and storing the result for future use.
In the Greedy Algorithm, the solution is built part by part. The decision to choose the next part is done on the basis that it gives the immediate benefit. It never considers the choices that had taken previously.
In Backtracking Algorithm, the problem is solved in an incremental way i.e. it is an algorithmic-technique for solving problems recursively by trying to build a solution incrementally, one piece at a time, removing those solutions that fail to satisfy the constraints of the problem at any point of time.
- 10 Important Android Studio Shortcuts You Need the Most
- Why Data Structures and Algorithms Are Important to Learn?
- Queries to find the left-most given type integer in a binary array
- Some important shortcuts in Competitive Programming
- Bits manipulation (Important tactics)
- Important Topics for GATE 2020 Computer Science
- GATE CS 2019 important dates and links
- Why is programming important for first year or school students?
- GATE CS 2020 Important Official Dates
- Important functions of STL Components in C++
- Check whether an array can be made strictly decreasing by modifying at most one element
- Container with Most Water
- Lexicographically smallest string formed by removing at most one character
- Steps to reduce N to zero by subtracting its most significant digit at every step
- Print all numbers less than N with at-most 2 unique digits
- Length of longest consecutive ones by at most one swap in a Binary String
- Count distinct substrings that contain some characters at most k times
- Make a tree with n vertices , d diameter and at most vertex degree k
- Maximum subarray sum by flipping signs of at most K array elements
- Number of ways of scoring R runs in B balls with at most W wickets
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.