Data Structure Operations
Data Structure Operations are the basic operations performed on data elements to store, access, modify, and manage data efficiently. The common operations are insertion, deletion, traversal, searching, sorting, and merging.
| Operation | Meaning | Example |
|---|---|---|
| 1. Insertion | Adding a new element to a data structure | Insert 40 into [10, 20, 30] → [10, 20, 30, 40] |
| 2. Deletion | Removing an existing element | Delete 20 → [10, 30, 40] |
| 3. Traversal | Visiting/accessing each element of the data structure, usually once | Display all elements: 10 20 30 40 |
| 4. Searching | Finding a particular element in the data structure | Search for 30 |
| 5. Sorting | Arranging elements in a particular order, such as ascending or descending | [30, 10, 20] → [10, 20, 30] |
| 6. Merging | Combining two similar data structures into one | [10,20] + [30,40] → [10,20,30,40] |
| 7. Updating | Changing the value of an existing element | [10,20,30] → [10,25,30] |
1. Insertion
Insertion means adding a new data element to an existing data structure.
For example:
Before: 10 20 30
Insert: 40
After: 10 20 30 40The position of insertion depends on the data structure. In an array, an element may be inserted at the beginning, middle, or end.
2. Deletion
Deletion means removing an existing element from a data structure.
Before: 10 20 30 40
Delete: 30
After: 10 20 40After deletion, the remaining elements may need to be rearranged depending on the data structure.
3. Traversal
Traversal means visiting each element of a data structure systematically.
For an array:
int A[5] = {10, 20, 30, 40, 50};
for(int i = 0; i < 5; i++)
cout << A[i] << " ";Output:
10 20 30 40 50Traversal is particularly important because many other operations, such as searching and displaying data, require traversal.
4. Searching
Searching means finding whether a particular element exists in the data structure and, if required, determining its position.
Example:
Data: 10 20 30 40 50
Search: 30
Result: Element found at position 3Common searching techniques include:
Linear Search
Binary Search
5. Sorting
Sorting means arranging data elements according to a specified order.
Ascending:
40 10 30 20
↓
10 20 30 40Descending:
40 30 20 10Common sorting algorithms are Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, and Quick Sort.
6. Merging
Merging means combining two data structures of the same or compatible type into a single structure.
List 1: 10 20 30
List 2: 40 50 60
Merged: 10 20 30 40 50 607. Updating
Updating means replacing or modifying the value of an existing element.
Before: 10 20 30
↓
Change 20 to 25
After: 10 25 30In short
The basic operations on data structures can be remembered as:
Insertion → Deletion → Traversal → Searching → Sorting → Merging → Updating
For an introductory Data Structures lecture, the first three—Insertion, Deletion, and Traversal—are especially important because they form the foundation for understanding arrays, linked lists, stacks, queues, and other data structures.
No comments:
Post a Comment