In this tutorial, we will discuss about data structures from the basics. We will understand the different types of data structures and their uses and how we can implement them.
What is data structure?
A data structure is a collection of data that can be stored in an organised manner so that the data can be accessed, modified efficiently.
Data Structures usages
- Data structures are used in different kinds of applications like relational databases, which use B-tree indexes to retrieve the data.
- Hash table is used in compiler design.
- These are used in different algorithms like searching, sorting.
- Internet indexing service uses data structures.
Types of the Data structures
|Types of DS||Sub type|
|Binary Search Tree|
What is Linear data structure ?
A linear data structure is a type of data structure where data can be traversed sequentially. Array, Linked list, stack, queue are examples of linear data structure. Please go through below image for the details:
What is Tree Data Structure
A tree data structure is a hierarchical data structure. It has nodes that are connected by edges.Please go through below image for the details:
What is hashing
Hashing is a data structure which uses a hash function to map the data in a key-value pair to retrieve the data faster. Examples of Hashing are Hash table, Hash tree. Please go through below image for the details:
What is graph
A Graph is a non-linear, pictorial representation of data consisting of edges and vertices. Please go through below image for the details:
Difference between linear and non-linear data structure
|Sl No||Key points||Linear data structure||Non-linear data structure|
|1||Data alignment||Data gets stored sequentially||Data gets stored in hierarchy form|
|2||Levels||Single level involved||Multiple level involved|
|3||Complexity||Easy to implement||Implementation is complex|
|4||Traversal||Data can be traversed in single run||Data cannot be traversed in a single run rather need multiple runs|
|5||Utilisation of memory||Not efficient||Efficient|
|6||Examples||Array, Linked list, stack, queue||Graph, tree|
|7||Application||Used in software development||Used in Image Processing, Voice Processing, Artificial Intelligence|
Some import Questions and Answers on Data Structure
Qn 1. What do you mean by ADT in Data structure?
Ans: ADT means Abstract Data type. Class or Objects are an example of ADT. When We use and Class or Object, we define the behavior by a set of values and a set of operations. ADT only tells us what operation has to perform. It does not tell us how the operation has been internally implemented.
For Example :
- size() -> Size gives us the number of elements, but it does not show how internally it calculates to give the result.
- insert(x) -> insert helps us to insert the element but does not tell how the logic is written.
- remove(x) -> Similarly remove method is used to remove the elements without telling the implementation.
- get(i) -> get is used to access the elements.
Qn 2. What are the advantages of data structure?
- Using Data Structure, we can efficiently store data in a storage device.
- Data structure gives an easy option to retrieve the data from a storage device.
- It can process small as well as large numbers of data efficiently
- Using data structures like graph we can solve real-life problems
- Database systems uses indexing using a hash table and array to retrieve the data efficiently.
Qn 3. What is primitive data structure?
Ans: Primitive data structures are system-defined data types supported by different programming languages. Example: int, double, float, boolean, character.
Qn 4. What is a Complex Data structure?
Ans: Data structures like Hash table, Tree, Heap, Graph are called a complex data structure. The implementation of these data structures is complex in nature.
Qn 5. What are the two main types of data structure?
Ans: Mainly, data structures are divided into two parts:
- Linear Data structure: Stack, Queue, Array, Linked List
- Non-linear Data Structure: Tree, Graph