So, what IS an algorithm?
Table of Contents
Whether we realize it or not, algorithms are a big part of our daily lives. Not only are they in the most mundane tasks, but they are also part of any computing device we put our hands on. But what exactly are they? How do they work? Which ones should you keep in mind if you want to dive into computer programming? In this article, we take a look at this and more!
We’ll start with the basics and go over exactly what an algorithm is and how it works. Also, we’ll cover some of the different types of algorithms.
What is an Algorithm?
To put it in simple terms, an algorithm is a set of instructions followed to complete a task or solve a problem. Although they may sound like a complex concept, we actually use algorithms daily. For instance, when we follow a recipe or solve a long division. When it comes to computer science, the one reading the algorithm is the computer. In this case, algorithms are like very detailed recipes or instruction manuals. As a result, computers read them to function the way we’d like them to.
What are Data Structures?
Data structures are a way of organizing and storing data in a virtual system so they’re used in an efficient way. These common data structures include arrays, stacks and queues. Why are we mentioning data structures here? Well, algorithms solve problems by processing data. Thus, they are often combined with algorithms. To do so, it optimizes code and builds computer programs. If you want to learn more about data structures, you can click here.
How do Algorithms work?
In the context of computing, algorithms work on the basis of input and output. An algorithm provides a computer with the input it needs to carry out the relevant steps. After that, it outputs the results.
Types of Algorithms
Algorithms come in a variety of forms, shapes and sizes. We’ll go over the most important ones below.
This algorithm is quite essential as it’s used to arrange the order of an array or list of elements. Sorting algorithms are usually classified into integer sorts and comparison sorts. Integer sorts —or counting sorts— determine how many elements in the array are less than X for any X element. Meanwhile, comparison sorts compare elements in the array. As a consequence, these determine if an element should be placed left or right of another one. Some popular sorting algorithms include bubble sort, merge sort and heap sort.
Divide and Conquer Algorithms
These algorithms divide the problem into subproblems of the same type. After solving —or conquering— each of them, they are all combined to solve the original problem. This type of algorithm is often used for binary search and matrix multiplication. Some algorithms that follow this logic include quicksort and closest pair of points.
The concept behind these algorithms is quite simple: to find an element in a data set. Searching algorithms get divided into sequential and interval searches. Some searching algorithms include binary search, breadth-first search, and depth-first search.
Brute Force Algorithms
The idea behind these algorithms is also quite simple. They iterate all possible solutions until they find a satisfactory one. You can think about it as trying every possible combination to open a safe.
Like with Divide and Conquer, this computer algorithm divides the problem into subproblems. Only one subproblem gets solved at the time. If a solution fails, the last step is undone and the algorithm backtracks to find another solution. The idea is to build the solution incrementally and remove those solutions that don’t adapt to the constraints of the problem at any point. You can use backtracking algorithms to solve the Knight’s tour problem or a Sudoku game. This algorithm is also popular for all binary strings and the knapsack problem.
Here, the simplest version of a problem gets solved first. Then, it moves on to larger versions of the problem until you find the solution to the original problem. There are different types of recursion. Among them, there are direct, indirect, tailed and non-tailed recursion. This is a good type of algorithm to solve the Tower of Hanoi problem or the DFS of a graph.
Dynamic Programming Algorithms
This is a very efficient way to solve a problem. Like in other algorithms in this list, a problem is divided into a set of simpler subproblems. Each of them get a fix once, and the solution to the complicated bigger problem is then computed. Yet, the solutions to the subproblems are stored for future use. It’s used for matrix chain multiplication, and the longest common subsequence, among others.
In a greedy algorithm, the first step is to find an optimal local solution. With this, it hopes to find an optimal global solution. This algorithmic paradigm builds on the solution piece by piece. To do so, it chooses the piece that offers the most immediate benefit first. Because there are no future considerations involved, this algorithm does not always work. But, when it does, it’s great to solve optimization problems. It’s applied for sorting, job scheduling, and for the coin change problem.
These computer algorithms make a decision based on random numbers. To do so, probability is their most important aspect. Randomized algorithms get classified into Las Vegas and Monte Carlo algorithms. The first always produces optimal or correct results. Meanwhile, the latter produces optimal or correct results with some probability. Randomized algorithms are applied for load balancing and rumor blocking in social media.
How are Algorithms used in Computer Science?
Since they’re the backbone of computer science, algorithms are everywhere you look. After all, it is through algorithms that computers function. Computer programs are pretty much algorithms written in a language that machines understand. Also, they play a significant role in the things we are exposed to online. For instance, it’s used to determine Google results, and the ads or the social media posts you see. The list of how computer science uses algorithms is endless. So, we’ll mention some other real-life applications of algorithms and data structures.
• An array data structure with a sorting algorithm is helpful to sort contacts in your phone.
• Graph data structure allows you to do a breadth-first-search to find people on a social network.
• The Divide and Conquer algorithm lets you find the maximum and the minimum in a data array.
• Backtracking algorithm applies, for example, for solving crossword puzzles.
• You can use a circular linked list to keep track of turns in a multiplayer game.
Why are Algorithms Important?
Algorithms are a great way to develop logical thinking skills on educational levels. As a result, children and teenagers develop cross-disciplinary skills. These lead them to create original solutions. Moreover, algorithms are a big part of Machine Learning and Artificial Intelligence. Both of them are very prominent programming fields. Behind Artificial Intelligence (AI) lies a simple concept. This is the fact that computers can learn based on existing decision-making examples.
These algorithms can work with both structured and unstructured data. Machine Learning (ML) is a subfield of artificial intelligence. But, it can only work with structured data. This is what sets it apart from the main field of AI. AI and ML algorithms are often used for data mining and pattern recognition. To put it in a plain way, ML is what makes it possible for Netflix to give you recommendations. Also, it’s what allows Facebook to determine what to show on your news feed.
What Makes a Good Algorithm?
Algorithms must follow certain rules or features to be good or efficient, like anything relating to code. Though it might sound obvious, the first thing to consider when it comes to a good algorithm is for it to be correct. This means it needs to have the correct output for each set of inputs. Moreover, both the input and the output should be properly specified. This encompasses all its relevant details. Algorithms should also be time and memory efficient. Further, they should have a finite number of steps and be easy to understand and install.
Advantages and Disadvantages
We’ve established that algorithms are an inherent part of life. However, we still think it’s worthwhile to list some of their advantages and disadvantages.
• Algorithms are quite easy to understand. They are a step-by-step representation of a solution to a given problem.
• They don’t depend on any specific programming language. This fact also makes them easy to understand.
• Algorithms can be broken down into pieces. As a result, it’s easier to put them in place and turn them into a program.
• They use a definite procedure.
• Because the steps in an algorithm have a logical sequence, they are easy to debug.
• Algorithms also help us make rational decisions.
• Algorithms are time-consuming. It takes a long time to write and apply them in a programming language.
• It’s difficult to create algorithms for large tasks.
• Looping and branching are not exactly easy to show in algorithms
Has this article sparked your curiosity about algorithms? Here are some learning resources for you to explore.
• Beginner’s Guide to Algorithmic Thinking.
• GeeksforGeeks' Introduction to Algorithms.
• Udacity’s Intro to Algorithms (free).
• Introduction to Algorithms (book)
• Dynamic Programming course at Udemy.
• Data Structures and Algorithms course from Codecademy.
• Algorithms Specialization, a Coursera's course from Stanford University.
Also, you can get practice from sites like:
We have covered what algorithms are, as well as their uses. Also, we looked into its different types. What’s even more, now you have plenty of links and resources to help you learn more about this topic. We hope this article gives you an idea of how algorithms work, and the important role they play in our daily lives. Moreover, we hope we’ve made it easy to understand these concepts and made you curious enough to find out even more!
A lot of the things of our daily lives are handled by algorithms. Is your team searching for be at advance-guard with some of the modern algorithms for your business? Or are you trying to improve the ones you've already have? We can create amazing things together! Let's start with getting in contact, the sky is the limit!