Data Structures and Algorithms (DSA)
-
Data Structures
Data Structures are a way of storing data to manage it efficiently. Managing efficiently means, accessing and manipulating its data in the fastest possible way and also using the least amount of resources (memory). A Data Structure contains a collection of data, stored in linear or non-linear formats according to different needs.
As an example, the folders in your computer can be best represented using a non-linear Tree data structure, since folders needs to maintain a hierarchical order.
And if we want to represent a group of students in a class, an Array data structure may be best suited.
Data structures becomes particularly useful when we are going to manage huge amount of data. If you are required to design such a system, make sure to identify the right data structures and algorithms to use before proceeding to next steps.
Most high level programming languages provide built-in support for certain types of data structures like Arrays and built-in methods along with it, so that we can use arrays as a Queue, Stack, etc.
Algorithms
Now that we got some basic info on Data Structures, let's do the same for Algorithms as well. These two go hand-in-hand, when we look into topics like Computer Science, Machine Learning, Data Science, etc.
Algorithms are a collection of instructions for doing a particular task. Algorithms usually expects on one or more input parameters and provide an output (result) at the end.
See below a simple algorithm to find the biggest of 2 numbers.
- Start.
- Enter n1 and n2.
- Check n1 > n2.
- If true, display n1. Go to step 8.
- If false, check n2 > n1.
- If true, display n2. Go to step 8.
- If false, display n1=n2. Go to step 8.
- Stop
We need algorithms to perform data structure tasks like search, traversals, etc. And for most of these kind of standard tasks, best possible algorithms as already been written.
Data Structures and Algorithms
Now you might have understood, Data Structures and Algorithms (DSA) is all about learning to use the right type of Data Structure for your data and choosing the most efficient Algorithm to perform a task.
In a series of articles, we will cover the most important concepts of Data Structures and Algorithms (DSA). Everything is explained in simple steps with examples. Please follow this tutorial step-by-step to understand different data structures and most used algorithms. Also try to implement the algorithms in your favorite programming language.
Also note that, we might often find that our requirements may not exactly match what these already defined algorithms are achieving. But in most of the cases, we can get the desired output by doing slight modifications on these algorithms. Or new algorithms can be written keeping the original ones as reference as per our need.
For example, think of a solution to find the shortest possible path between 2 points in a map. Maps are essentially nodes(points) spread across two or three dimensional surfaces.
We can find the path be going through each node and check for possible directions from each. This will give us multiple possible paths and we will have to get the shortest path by counting number of nodes.
But this is essentially a brute-force search and will consume a lot of time and resources.Best possible solution might be to go for the Breadth First Search (BFS) Algorithm on a Graph data structure. BFS is a recursive algorithm to search all possible nodes of a tree or graph. By making slight modifications to the algorithm, shortest path can be found and this is way more efficient compared the first approach. -
Relevance of DSA
In today's world of computing, data is everything. Top companies like Google, Facebook, etc manages huge amounts of data. They maintain these data across multiple locations using vast amounts of servers. But storing the data alone is not just enough.
Data has to be maintained in a structured manner so that it can be fetched or traversed or perform any other operations in the fastest possible way. This is where Data Structures and Algorithms (DSA) becomes relevant.
DSA helps in reducing the time and space complexities of a task like searching for an information from a group of data.
You will find that in the recruitment process of most of these high-end tech companies, knowledge on DSA is the most focused topic. A thorough knowledge in DSA helps to advance your career and surely will help in improving your programming skills.
So why wait!!! Lets start.