Page 22 - DCAP407_DATA_STRUCTURE
P. 22
Unit 1: Introduction to Data Structures
1.5 Data Structure Operations
Data which appears in the data structures are processed with the help of certain operations. Sometimes
two or more of the operations may be used in a given situation.
When you want to delete a record with a given key, you first need to use the
search operation to find the location of the record and then use the delete
operation.
1.5.1 Operations on Primitive Data Structure
Various operations can be performed on primitive data structures. Some of these operations are:
1. Creation Operation: The creation operation creates a data structure.
Consider an example of integer type data structure.
int a;
Here, declaration of int creates 2 bytes of memory space for variable ‘a’. This
variable is used to store only integer value.
2. Destroy Operation: The destroy operation destroys the data structure. In C language, a function
called ‘free()’ is used to destroy the data structure. This helps in efficient use of memory.
3. Selection Operation: The selection operation is used to access data within a data structure. The
significance of selection operation is provided in file data structure. Files provide the option of
sequential and random access, which totally depend on the nature of files.
4. Update Operation: The update operation is used to modify data in data structure.
1.5.2 Operations on Non-primitive Data Structure
The operations on non-primitive data structure depend on the logical organization of data and their
storage structure. Non-primitive data focuses on formation of a set of data elements that are either
homogeneous (same data type) or heterogeneous (different data type). Therefore, non-primitive data
cannot be operated or manipulated directly by the machine level instructions. Some of the operations on
non-primitive data structure are:
1. Traversing: Traversing is the method of processing each element exactly once. Traversing is
generally done to check the availability of data elements in an array. After carrying out an
insertion or deletion operation, you would want to check whether the operation has been
successful or not. We use traversing to check if the element is successfully inserted or deleted.
2. Sorting: Sorting is the technique of arranging the data elements in some logical order, either
ascending or descending order. Some algorithms make use of sorted lists. Therefore, efficient
sorting is essential for optimizing these algorithms to ensure that they work correctly.
3. Merging: Merging is the method of combining the elements in two different sorted lists into a
single sorted list. It is based on the divide-and-conquer algorithm. Merge sort can be considered as
the best choice for sorting a linked list as it is easy to implement.
4. Searching: Searching is the method of finding the location of an element with a given key value, or
finding the location of an element which satisfies a given condition. Searching a data structure
allows the efficient retrieval of unambiguous items from a set of items, such as a particular record
from a database.
5. Insertion: Insertion is the method of adding a new element to the data structure. The insertion
process may add a new element in the i position of the data structure. If sorting also needs to be
th
performed, first we need to assign an item to the given elements and compare it with the previous
elements. If the assigned element is smaller than the previous element, we need to swap the
positions of both these items. This process is repeated until the correct position of the item is
identified.
LOVELY PROFESSIONAL UNIVERSITY 15