What Is An Algorithm?
In mathematics and computer science, an algorithm is a finite sequence of well-defined instructions, typically used to solve a class of specific problems or to perform a computation.
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
example,
An algorithm to add two numbers:
Take two number inputs
Add numbers using the + operator
Display the result
Important basic rules to follow
- Input and output should be defined precisely.
- Each step in the algorithm should be clear and unambiguous.
- Algorithms should be most effective among many different ways to solve a problem.
Why are Algorithms Important ?
The ability to define clear steps to solve a problem, is crucial in many different fields. Knowingly or unknowingly, we use algorithms and algorithmic thinking all the time. It allows us to break down problems and find the best possible solutions in terms of discrete steps.
The efficiency of an algorithm depends on two parameters:
1. Time Complexity
2. Space Complexity
**Time Complexity: **Time Complexity is defined as the number of times a particular instruction set is executed rather than the total time is taken. It is because the total time taken also depends on some external factors like the compiler used, processor’s speed, etc.
**Space Complexity: **Space Complexity is the total memory space required by the program for its execution.
Types of Algorithms
Algorithms are classified based on the concepts that they use to accomplish a tasks. Below are the widely known and widely used few algorithm techniques.
Divide and conquer algorithms –
In Divide and Conquer algorithms, the idea is to solve the problem in two sections, Divide the problem into smaller subproblems of the same type; solve those smaller problems, and combine those solutions to solve the original problem.
Brute force algorithms –
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 try all possible solutions until a satisfactory solution is found.
Greedy algorithms –
Find an optimal solution at the local level with the intent of finding an optimal solution for the whole problem.
Recursive algorithms –
Solve the lowest and simplest version of a problem to then solve increasingly larger versions of the problem until the solution to the original problem is found.
Backtracking algorithms –
Divide the problem into subproblems, each which can be attempted to be solved; however, if the desired solution is not reached, move backwards in the problem until a path is found that moves it forward.
Dynamic programming algorithms –
This type of algorithm is also known as the memorization 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.
Break a complex problem into a collection of simpler subproblems, then solve each of those subproblems only once, storing their solution for future use instead of re-computing their solutions.
Sorting Algorithms
A sorting algorithm is an algorithm that puts elements of a list in a certain order. Sorting is often an important first step in algorithms that solves more complex problems. There are a large number of sorting algorithms, each with their own benefits and costs. Below, we will focus on some of the more famous sorting algorithms.
Linear sort:
Find the smallest element in the list to be sorted, add it to a new list, and remove it from the original list. Repeat this until the original list is empty.
Bubble sort:
Compare the first two elements in the list, and if the first is greater than the second, swap them. Repeat this with every pair of adjacent elements in the list. Then, repeat this process until the list is fully sorted.
Insertion sort:
Compare each element in the list to all the prior elements until a smaller element is found. Swap these two elements. Repeat this process until the list is fully sorted.
Top comments (0)