While learning data structures and algorithms, we feel very overwhelmed.
That's why this blog will help to understand basic concepts...
Let’s begin with what is Data Structure.
In simple terms, we can say that it’s a way to organize and store data in a much more efficient way.
That data can be in form of arrays[], strings ” ”, trees, graphs, stacks, and many more. We are going to look into this in detail.
Let's start with Arrays!…
Arrays are used to store collections of data, such as a list of names or a list of integers.
The size of an array usually starts with index 0.
One advantage of using arrays is that they are easy to implement and access, as they are stored in contiguous memory locations.
But the problem with the array is, its size is fixed. So whenever we want to do some changes we need to copy it into a new array, this method is time-consuming.
Real-World Example.
Arrays are used in e-commerce sites like Amazon and others. In that sites, we can see the option of filtering or sorting by price this function used the arrays of lists. so iteration can be easy.
Working_
Let’s move on to LinkedList!…
A linked list is a (linear data structure) that consists of a sequence of nodes, where each node stores a reference to the next node in the list.
Linked lists are useful for storing large amounts of data because they can grow and shrink dynamically.
But In LinkedList, we can make the changes whenever we want, with the help of the head, and reference of the next node.
Real-World Example.
A playlist of songs on a music streaming service is a linked list. Each song is a node, and the link is the next song in the playlist. The head of the list is the first song, and the tail is the last song🎶.
Working_
Now on to the next topic Stack!...
Stack is also basically a linear Data Structure that works on LIFO(last-in-first-out) principle.
It performs two main operations: 'push' which adds the element to the top of the stack and 'pop' operation which remove the element from the top of the stack.
Real-World Example.
Stacks are often used to implement undo functionality in text editors and to evaluate mathematical expressions.
Working_
The next Part is Queues...
A queue is a linear data structure that follows the first-in, first-out (FIFO) principle.
It has two main operations: enqueue, which adds an element to the back of the queue, and dequeue, which removes the element from the front of the queue.
Real-World Examples.
Queues are often used to store data that needs to be processed in a specific order, such as tasks in a task queue or customers in a queue at a store.
Working_
What are Trees!...
A tree is a hierarchical data structure that consists of nodes connected by edges. The top node is called the 'root', and the nodes below it are called 'children'.
Each node can have zero or more children, but only one parent (except for the root, which has no parent).
This is also an advanced topic, also frequently asked in a big tech company.
for traversing the tree the method uses are Postorder traversal, Preorder traversal, inorder traversal
Real-World Example.
Trees are often used to store data that has a hierarchical structure, such as the file system on a computer or the structure of a company.
Working_
Last But not least we have Graphs...
A graph is a data structure that consists of a set of vertices (or nodes) and a set of edges connecting them.
Graphs can be used to represent a wide variety of data, such as social networks, transportation systems, and the web.
There are many different types of graphs, including directed graphs (where the edges have a direction) and undirected graphs (where the edges have no direction).
In a directed graph, the edges have a direction and connect one vertex to another. These edges are also known as arcs.
In an undirected graph, the edges do not have a direction and connect pairs of vertices. These edges are also known as edges.
Real-World Example.
Example for directed graph - person A is friends with person B, but person B is not friends with person A.
Example for undirected graph - the road connects city A to city B and city B to city A.
Tip:
DSA is all about problem solving, and how you solve those real-world problems with a good complexity approach. Keep practicing.