Data is an essential part of every day, and organising and storing it is the real deal. It is stored in various ways and formats. It can be either a single set of values or multiple values. A data item refers to a single set of values in general. For example, the name of an employee can be considered as one data item. It can further be categorised as subitems, namely first name, middle, and last name. The employee id associated with the data item would be a single item.
Further, the address can have sub-items such as street and area. Just one employee is likely to have numerous data items and subitems related to it. To store and maintain the robustness of data, the concept of data structure comes in.
Data structure stores and organises a large set of data in computer memory. It ensures the reusability of data efficiently later. Data can be stored logically or mathematically. It can vary depending on the organisational needs and adaptability levels. The data models are adapted based on two factors:
- The structure was established to reflect the relation of data with real-world objects.
- Low level of complexity for reusability and robustness.
Types of data structures
In terms of relations
- Linear data structures
In linear data structures, the elements form a specific order. The data might be allocated linear memory such as an array, or else the data might point to each other as in the case of a linked list.
Examples of linear data structures include arrays, linked lists, stacks and queues.
- Non-linear data structures
The data structure represents the hierarchical relationship between elements.
Examples of non-linear data structure graphs, trees, heaps etc.
In terms of size
- Dynamic Data structures: The size of the data structure is variable and changes according to the data set. The memory is allocated at run-time for new items. It takes up only the required amount of space.
- Static Data structures: The size of the data structure is fixed. The memory is allocated at compile time.
Operations on Data Structures
The data is processed through a set of operations in both linear and non-linear data structures. The basic operations on data structures are listed below:
- Searching
- Sorting
- Insertion
- Traversing
- Merging
- Deletion
Characteristics of Data structures
- Data structures can be homogeneous or nonhomogeneous. Homogenous has the same data types of elements represented in the data structure, for example, array.
Non-homogenous might have different data types stored in the data structures.
- It ensures the robustness of data is maintained
- Data structure maximises the reusability of data
- It reduces memory usage during processing
- The execution time required for each process in the data structure is known as time complexity
- The space required for each process in the data structure is known as space complexity
Advantages of Data Structures
- The right choice of data structure used in a particular problem increases its efficiency and optimises the solution for low space and time complexity.
- When a particular data structure is implemented in a program, it can be used again in some other part of the program, depending on its scope. This increases the reusability and robustness of the data.
- It abstracts the data on the various level and hence confines the interaction of data and user up to interface only.
- Data Structure simplifies the process of storing and processing data in software.
Popular data structures and their usage
- Arrays: An array stores elements with the same data types in contiguous memory locations. Arrays can be one dimensional or two dimensional. It is a static and linear data structure. Arrays are generally used for operations like searching or sorting in a system. Every element inside an array has an index value attached to it.
- Linked list: Linked list contains nodes storing data and memory attached to it. The data is stored on a continuous memory location, and hence, the address stored in the node links it to the next address where the data is stored.
- Stack: Stack is a linear data structure which allows insertion and deletion through the open end. The insertion operation is known as push, while deletion is called pop.
- Queue: Another linear data structure where the operation follows FIFO( first in first out rule). Insertion in queues is known as enqueue, and deletion is known as dequeue.
- Graph: A graph is a non-linear data structure with nodes and edges. It connects other nodes in the graph and forms a graphical image of an object. The graph can be a directed or undirected graph. Directed graphs are connected in a single direction, while undirected graphs are bidirectional.
- Trees: Trees are non-linear data structures. It forms hierarchical relations with the data elements. The root node is the point from which the tree descends. A tree might have subtrees. It exhibits the parent-child relationship. The node that descends from a certain node is called a child node. A parent node can have multiple child nodes, but only one parent node.
Conclusion
Data structures allow systematic data storage for robustness and reusability. The correct implementation of data structure facilitates easy computing and manipulation of data as required. In software, there are thousands of programs running in the background, and each computer program utilises data structure to improve efficiency with space and time complexity.