Ans: Data Structure is an approach of organizing data, storing data and managing data so that we can access and modify it efficiently.
For example, Suppose we have some data of the students of class 4. As we know that every students have name, age and roll number in general.
If we consider a student whose name is “Pawan”, age is 17 and he is from class 4. Here “Pawan” name is of String data, and 17 and 1 is integer data.
If we have only one the data of single student then it is easy to manage and store. But what about if we have thousands of students data?
So for that purpose data structure concept is needed to handle the operations on that large amount of data.
Means we have to use array or linked list as per requirement to manage that much data and perform any desired operation on it efficiently.
In simple word, we can define data Structures as it is a structure programmed to store data in ordered form so that operations are often performed on that very easily. Also, represent the data in organized form to store in memory so that it should be increase the efficiency and reduces the complexity.
You can also remember it as Data Structure, is a method to store the data in a structured way so that it can be easily created, viewed, and managed.
Arrays- An array is a data structure that stores similar type of data in continuous memory location.
Here similar type of data means all elements have same data type.
Data is stored together in Continuous Memory Locations, the position of any element can be calculated or retrieved easily with the help of first element’s location or base location.
Each elements of an array have index value, with the help of it we can access the elements of any position.
The index value starts from the 0.
Stacks- A stacks are recursive data structures that follow the last-in-first-out (LIFO) principle or we can also say that first in last out (FILO) principle.
LIFO means the lastly pushed element in the stack pooped out first. Similarly FILO means first pushed element will pooped out at last.
Stack has two operations push and pop. Push means the item into the stack, and the pop means item out of the stack.
Elements in the stack can be added and removed only at the top.
Queues- A Queues is a data structures that follow the First In First Out (FIFO) principle.
FIFO means the first element that is inserted in the queue is the first element one, which will be removed first.
Elements are always added in Queues to the back, and it is removed from the front.
Linked lists- A linked list is a linear data structure where the elements are stored at non-contiguous memory locations.
It is a node based structure and each node have two fields, data and link.
Data stores the actual value or item and link stores the base address of next node means we can say that link has a reference of next node.
If there is no any next node then link will point to NULL.
Trees-Tree is an abstract and non-linear data type. It has a root node and child nodes and this all nodes are linked to each other with the help of edge.
We can also define it as it is a collection of nodes.
Graph- A Graph is a non-linear data structure which consists nodes and edges. Nodes are also known as vertices, and the edges are known as lines or arcs. This lines or arc connects two nodes in the graph. A computer network is a real-world example of Graphs.
Tries- A trie, or keyword tree, is a data structure that is based on the prefix of a string and stores strings as data items that can be can be visualized like a graph.
Hash tables- Hash tables is a data structure that stores data in a key/values pair. And there is a hash function that helps to generate key.
Why do we need data structures?
Data structures are important for the following reasons:
- Data structures are used in every program or software system to arrange the data.
- Data structures are essential ingredients of many efficient algorithms. It helps in the management of huge amounts of data, such as a large integrated collection of databases.
- Each Data Structure allows data/elements to be stored in a specific manner in the memory.
- Data Structure helps in efficient data search and retrieval.
- For specific problems, specific Data structures are used.
- Data Structure allows managing a large amount of data, such as large databases and indexing services such as a hash table.
- Data structures organized the storage and retrieval of data and information which is stored in both main memory and secondary memory.
Area where data structure is applied
- In Numerical analysis
- In Operating System
- In Artificial intelligence
- In Compiler design
- In Statistical analysis package
- In DBMS
- In Simulation
- In Graphics Design