Learn Data Structures and Algorithms
Here comes the most crucial and the most awaited stage of the roadmap for learning data structure and algorithm β the stage where you start learning about DSA. The topic of DSA consists of two parts:
- Data Structures
- Algorithms
Though they are two different things, they are highly interrelated, and it is very important to follow the right track to learn them most efficiently. If you are confused about which one to learn first, we recommend you to go through our detailed analysis on the topic: What should I learn first- Data Structures or Algorithms?
Here we have followed the flow of learning a data structure and then the most related and important algorithms used by that data structure.
3.1. Array
The most basic yet important data structure is the array. It is a linear data structure. An array is a collection of homogeneous data types where the elements are allocated contiguous memory. Because of the contiguous allocation of memory, any element of an array can be accessed in constant time. Each array element has a corresponding index number.
To learn more about arrays, refer to the article βIntroduction to Arraysβ.
Here are some topics about array which you must learn:
- Rotation of Array β Rotation of array means shifting the elements of an array in a circular manner i.e., in the case of right circular shift the last element becomes the first element, and all other element moves one point to the right.
- Rearranging an array β Rearrangement of array elements suggests the changing of an initial order of elements following some conditions or operations.
- Range queries in the array β Often you need to perform operations on a range of elements. These functions are known as range queries.
- Multidimensional array β These are arrays having more than one dimension. The most used one is the 2-dimensional array, commonly known as a matrix.
- Kadaneβs algorithm
- Dutch national flag algorithm
3.2. String
A string is also a type of array. It can be interpreted as an array of characters. But it has some special characteristics like the last character of a string is a null character to denote the end of the string. Also, there are some unique operations, like concatenation which concatenates two strings into one.
Here we are providing you with some must-know concepts of string:
- Subsequence and substring β A subsequence is a sequence that can be derived from a string deleting one or more elements. A substring is a contiguous segment of the string.
- Reverse and rotation in a string β Reverse operation is interchanging the position of characters of a string such that the first becomes the last, the second becomes the second last, and so on.
- Binary String β A binary string is a string made up of only two types of characters.
- Palindrome β A palindrome string is a string in which the elements at the same distance from the center of the string are the same.
- Lexicographic pattern β Lexicographical pattern is the pattern based on the ASCII value or can be said in dictionary order.
- Pattern searching β Pattern searching is searching a given pattern in the string. It is an advanced topic of string.
3.3. Linked List
As the above data structures, the linked list is also a linear data structure. But Linked List is different from Array in its configuration. It is not allocated to contiguous memory locations. Instead, each node of the linked list is allocated to some random memory space and the previous node maintains a pointer that points to this node. So no direct memory access of any node is possible and it is also dynamic i.e., the size of the linked list can be adjusted at any time. To learn more about linked lists refer to the article βIntroduction to Linked Listβ.
The topics which you must want to cover are:
- Singly Linked List β In this, each node of the linked list points only to its next node.
- Circular Linked List β This is the type of linked list where the last node points back to the head of the linked list.
- Doubly Linked List β In this case, each node of the linked list holds two pointers, one point to the next node and the other points to the previous node.
3.4. Searching Algorithm
Now we have learned about some linear data structures and is time to learn about some basic and most used algorithms which are hugely used in these types of data structures. One such algorithm is the searching algorithm.
Searching algorithms are used to find a specific element in an array, string, linked list, or some other data structure.
The most common searching algorithms are:
- Linear Search β In this searching algorithm, we check for the element iteratively from one end to the other.
- Binary Search β In this type of searching algorithm, we break the data structure into two equal parts and try to decide in which half we need to find for the element.
- Ternary Search β In this case, the array is divided into three parts, and based on the values at partitioning positions we decide the segment where we need to find the required element.
Besides these, there are other searching algorithms also like
3.5. Sorting Algorithm
Here is one other most used algorithm. Often we need to arrange or sort data as per a specific condition. The sorting algorithm is the one that is used in these cases. Based on conditions we can sort a set of homogeneous data in order like sorting an array in increasing or decreasing order.
Sorting Algorithm is used to rearrange a given array or list elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of element in the respective data structure.
There are a lot of different types of sorting algorithms. Some widely used algorithms are:
- Bubble Sort
- Selection Sort
- Insertion Sort
- Quick Sort
- Merge Sort
There are several other sorting algorithms also and they are beneficial in different cases. You can learn about them and more in our dedicated article on Sorting algorithms.
3.6. Divide and Conquer Algorithm
This is one interesting and important algorithm to be learned in your path of programming. As the name suggests, it breaks the problem into parts, then solves each part and after that again merges the solved subtasks to get the actual problem solved.
Divide and Conquer is an algorithmic paradigm. A typical Divide and Conquer algorithm solves a problem using following three steps.
- Divide: Break the given problem into subproblems of same type.
- Conquer: Recursively solve these subproblems
- Combine: Appropriately combine the answers
This is the primary technique mentioned in the two sorting algorithms Merge Sort and Quick Sort which are mentioned earlier. To learn more about the technique, the cases where it is used, and its implementation and solve some interesting problems, please refer to the dedicated article Divide and Conquer Algorithm.
3.7. Stack
Now you should move to some more complex data structures, such as Stack and Queue.
Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
The reason why Stack is considered a complex data structure is that it uses other data structures for implementation, such as Arrays, Linked lists, etc. based on the characteristics and features of Stack data structure.
3.8. Queue
Another data structure that is similar to Stack, yet different in its characteristics, is Queue.
A Queue is a linear structure which follows First In First Out (FIFO) approach in its individual operations.
A queue can be of different types like
- Circular queue β In a circular queue the last element is connected to the first element of the queue
- Double-ended queue (or known as deque) β A double-ended queue is a special type of queue where one can perform the operations from both ends of the queue.
- Priority queue β It is a special type of queue where the elements are arranged as per their priority. A low priority element is dequeued after a high priority element.
3.9. Tree Data Structure
After having the basics covered about the linear data structure, now it is time to take a step forward to learn about the non-linear data structures. The first non-linear data structure you should learn is the tree.
Tree data structure is similar to a tree we see in nature but it is upside down. It also has a root and leaves. The root is the first node of the tree and the leaves are the ones at the bottom-most level. The special characteristic of a tree is that there is only one path to go from any of its nodes to any other node.
Based on the maximum number of children of a node of the tree it can be β
- Binary tree β This is a special type of tree where each node can have a maximum of 2 children.
- Ternary tree β This is a special type of tree where each node can have a maximum of 3 children.
- N-ary tree β In this type of tree, a node can have at most N children.
Based on the configuration of nodes there are also several classifications. Some of them are:
- Complete Binary Tree β In this type of binary tree all the levels are filled except maybe for the last level. But the last level elements are filled as left as possible.
- Perfect Binary Tree β A perfect binary tree has all the levels filled
- Binary Search Tree β A binary search tree is a special type of binary tree where the smaller node is put to the left of a node and a higher value node is put to the right of a node
- Ternary Search Tree β It is similar to a binary search tree, except for the fact that here one element can have at most 3 children.
3.10. Graph Data Structure
Another important non-linear data structure is the graph. It is similar to the Tree data structure, with the difference that there is no particular root or leaf node, and it can be traversed in any order.
A Graph is a non-linear data structure consisting of a finite set of vertices(or nodes) and a set of edges that connect a pair of nodes.
Each edge shows a connection between a pair of nodes. This data structure helps solve many real-life problems. Based on the orientation of the edges and the nodes there are various types of graphs.
Here are some must to know concepts of graphs:
- Types of graphs β There are different types of graphs based on connectivity or weights of nodes.
- Introduction to BFS and DFS β These are the algorithms for traversing through a graph
- Cycles in a graph β Cycles are a series of connections following which we will be moving in a loop.
- Topological sorting in the graph
- Minimum Spanning tree in graph
3.11. Greedy methodology
As the name suggests, this algorithm builds up the solution one piece at a time and chooses the next piece which gives the most obvious and immediate benefit i.e., which is the most optimal choice at that moment. So the problems where choosing locally optimal also leads to the global solutions are best fit for Greedy.
For example, consider the Fractional Knapsack Problem. The local optimal strategy is to choose the item that has maximum value vs weight ratio. This strategy also leads to a globally optimal solution because we are allowed to take fractions of an item.
Here is how you can get started with the Greedy algorithm with the help of relevant sub-topics:
3.12. Recursion
Recursion is one of the most important algorithms which uses the concept of code reusability and repeated usage of the same piece of code.
The point which makes Recursion one of the most used algorithms is that it forms the base for many other algorithms such as:
In Recursion, you can follow the below articles/links to get the most out of it:
3.13. Backtracking Algorithm
As mentioned earlier, the Backtracking algorithm is derived from the Recursion algorithm, with the option to revert if a recursive solution fails, i.e. in case a solution fails, the program traces back to the moment where it failed and builds on another solution. So basically it tries out all the possible solutions and finds the correct one.
Backtracking 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
Some important and most common problems of backtracking algorithms, that you must solve before moving ahead, are:
3.14. Dynamic Programming
Another crucial algorithm is dynamic programming. Dynamic Programming is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming.
The main concept of the Dynamic Programming algorithm is to use the previously calculated result to avoid repeated calculations of the same subtask which helps in reducing the time complexity.
To learn more about dynamic programming and practice some interesting problems related to it, refer to the following articles:
Complete Roadmap To Learn DSA From Scratch
Todayβs world is highly reliable on data and their appropriate management through widely used apps and software. The backbone for appropriate management of data is Data Structure and Algorithms (for convenience here we will use the term DSA). It is a dream for many to achieve expertise in handling and creating these apps and software. With this target in mind, they set out on the journey of learning DSA. The very first step in the journey is the creation of a complete roadmap to learn data structure and algorithms.
Here in this article, we will try to make that task easy for you. We will be providing here with a complete roadmap for learning data structure and algorithms for anyone keen to learn DSA, from scratch.
Table of Contents/Roadmap
- 5 steps to learn DSA from scratch
- Learn at least one Programming Language
- Learn about Complexities
- Learn Data Structure and Algorithms
- 1) Array
- 2) String
- 3) Linked List
- 4) Searching Algorithm
- 5) Sorting Algorithm
- 6) Divide and Conquer Algorithm
- 7) Stack
- 8) Queue
- 9) Tree Data Structure
- 10) Graph Data Structure
- 11) Greedy Methodology
- 12) Recursion
- 13) Backtracking Algorithm
- 14) Dynamic Programming
- Practice, practice and practice more
- Compete and become a pro
- Tips to boost your learning
- Learn the Fundamentals of chosen Language properly
- Get a good grasp of the Complexity Analysis
- Focus on Logic Building
- Donβt worry if stuck on a problem
- Be consistent
- Conclusion
From creating Games to building Social Media Algorithms. DSA plays an integral part whether you want to build something of your own or either may be willing to get a job in big tech giants like Google, Microsoft, Netflix and more. This time, learn DSA with us, with our most popular DSA course, trusted by over 75,000 students! Designed by leading experts having years of industry expertise, which gives you a complete package of video lectures, practice problems, quizzes, and contests. Get started!