Data Structures Operations

Data Structure

Data Structure एक तरीका है, जिससे हम Data को इस तरह से Store और Organize करते हैं, कि उसे Efficient तरीके से Access और Modify किया जा सके।

Data Structure के Types

  1. Linear Data Structures – जैसे Array, Linked List, Stack, Queue
  2. Non-Linear Data Structures – जैसे Tree, Graph
  3. Hash-based Structures – जैसे Hash Table
  4. File-based / Indexed Structures – Database में उपयोग होने वाले हर Structure के अपने Operations होते हैं, जिनकी Cost अलग-अलग होती है।

Data Structure Operations (डेटा स्ट्रक्चर operations)

  1. Traversing :
    किसी Data Structure के हर Element को एक बार Visit करना।
    Example : जैसे आप Paytm Wallet में पिछले 10 Transactions देखना चाहते हैं — System हर Transaction को एक बार Traverse करेगा।

#include <stdio.h>

int main() {
int arr[5] = {10, 20, 30, 40, 50};
int i;

printf(“Array Traversing:\n”);
for(i = 0; i < 5; i++) {
printf(“Element %d = %d\n”, i, arr[i]);
}

return 0;
}

				
					Output :
Array Traversing:
Element 0 = 10
Element 1 = 20
Element 2 = 30
Element 3 = 40
Element 4 = 50

				
			
  1. Insertion :
    Structure में नया Data Add करना। जैसे – Flipkart Database में नया Product जोड़ना।
    Example :
    Array में नया Element जोड़ना
    Linked List में नया Node Insert करना
    Binary Search Tree में नया Value डालना

#include <stdio.h>

int main() {
int arr[10] = {10, 20, 30, 40, 50};
int size = 5;
int pos = 3; // 3rd position par insert karna hai
int value = 25;

// Elements ko right shift karna
for (int i = size; i >= pos; i–) {
arr[i] = arr[i – 1];
}

arr[pos – 1] = value; // Insert new element
size++;

printf(“After Insertion:\n”);
for (int i = 0; i < size; i++) {
printf(“%d “, arr[i]);
}

return 0;
}

				
					Output :
After Insertion:
10 20 25 30 40 50
				
			

        3. Deletion (डिलीशन) :
            किसी Element को Remove करना।
            Example : Gmail में पुराने ईमेल Delete करना।

#include <stdio.h>

int main() {
int arr[10] = {10, 20, 30, 40, 50};
int size = 5;
int pos = 3; // तीसरे position का element delete करना है

printf(“Before Deletion:\n”);
for (int i = 0; i < size; i++) {
printf(“%d “, arr[i]);
}

// Element delete करना
for (int i = pos – 1; i < size – 1; i++) {
arr[i] = arr[i + 1];
}
size–;

printf(“\n\nAfter Deletion:\n”);
for (int i = 0; i < size; i++) {
printf(“%d “, arr[i]);
}

return 0;
}

				
					Output :
Before Deletion:
10 20 30 40 50

After Deletion:
10 20 40 50
				
			

        4. Searching :
            किसी Data Structure में किसी Particular Item को ढूँढना।
            Example :

    • IRCTC में Train Number सर्च करना
    • Google Contacts में किसी Name को खोजना

#include <stdio.h>

int main() {
int arr[10] = {10, 20, 30, 40, 50};
int size = 5;
int pos = 3; // तीसरे position का element delete करना है

printf(“Before Deletion:\n”);
for (int i = 0; i < size; i++) {
printf(“%d “, arr[i]);
}

// Element delete करना
for (int i = pos – 1; i < size – 1; i++) {
arr[i] = arr[i + 1];
}
size–;

printf(“\n\nAfter Deletion:\n”);
for (int i = 0; i < size; i++) {
printf(“%d “, arr[i]);
}

return 0;
}

				
					Output :
Before Deletion:
10 20 30 40 50

After Deletion:
10 20 40 50
				
			

        5. Sorting :
            Data को किसी Order (Ascending/Descending) में Arrange करना।
            Example : Flipkart Price Low to High या High to Low में Products दिखाता है।

Common Algorithms :

      • Bubble Sort – O(n²)
      • Selection Sort – O(n²)
      • Insertion Sort – O(n²)
      • Merge Sort – O(n log n)
      • Quick Sort – O(n log n)
      • Heap Sort – O(n log n)

#include <stdio.h>

int main() {
int arr[5] = {50, 10, 40, 20, 30};
int n = 5;

for (int i = 0; i < n – 1; i++) {
for (int j = 0; j < n – i – 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}

printf(“After Bubble Sort:\n”);
for (int i = 0; i < n; i++) {
printf(“%d “, arr[i]);
}
return 0;
}

				
					Output :
After Bubble Sort:
10 20 30 40 50
				
			

       6. Merging :
            दो या अधिक Data Sets को Combine करना।
            Example : IRCTC के Data Center में जब दो अलग-अलग Server की Train Lists Merge की जाती हैं।

#include <stdio.h>

int main() {
int arr1[3] = {10, 20, 30};
int arr2[3] = {40, 50, 60};
int merged[6];
int i, j, k = 0;

// First array copy
for (i = 0; i < 3; i++) {
merged[k] = arr1[i];
k++;
}

// Second array copy
for (j = 0; j < 3; j++) {
merged[k] = arr2[j];
k++;
}

printf(“Merged Array:\n”);
for (i = 0; i < 6; i++) {
printf(“%d “, merged[i]);
}

return 0;
}

				
					Output :
Merged Array:
10 20 30 40 50 60
				
			

 

  1. Updating (अपडेटिंग) :
    किसी Existing Element का Value Change करना।
    Example : Paytm Profile में Address Update करना।

#include <stdio.h>

int main() {
int arr[5] = {10, 20, 30, 40, 50};
int pos = 3; // तीसरी position पर element update करना है
int newValue = 35;

printf(“Before Updating:\n”);
for (int i = 0; i < 5; i++) {
printf(“%d “, arr[i]);
}

// Update Operation
arr[pos – 1] = newValue;

printf(“\n\nAfter Updating:\n”);
for (int i = 0; i < 5; i++) {
printf(“%d “, arr[i]);
}

return 0;
}

				
					Output :
Before Updating:
10 20 30 40 50

After Updating:
10 20 35 40 50
				
			

Data Structure Cost Estimation

Cost Estimation दो चीज़ों पर आधारित होती है :

  1. Time Complexity (समय जटिलता)
  2. Space Complexity (स्थान जटिलता)

1. Time Complexity (समय जटिलता)

Time Complexity बताता है कि किसी Algorithm या Operation को Run करने में कितना समय लगेगा।

Notation System

  • O(1) → Constant Time
  • O(log n) → Logarithmic
  • O(n) → Linear
  • O(n log n) → Quasi-linear
  • O(n²) → Quadratic

Example :

Operation

Complexity

Example

Access in Array

O(1)

arr[5]

Search in Linked List

O(n)

Linear Traversal

Insert in Stack

O(1)

Push Operation

Sort (Quick Sort)

O(n log n)

Sorting IDs

2. Space Complexity (स्थान जटिलता)

Space Complexity बताती है कि किसी Operation को Perform करने के लिए कितनी Memory चाहिए।

Formula :
Total Space = Fixed Space + Variable Space

Example :

For an Array of n elements → Space = O(n)

For a Recursive Function → Space = O(n) (due to call stack)

Example :
ISRO में Satellite Telemetry Data को Process करने के लिए Space Optimization बहुत जरूरी होता है क्योंकि High Memory मतलब High Cost!

Operation – wise Cost Summary

Operation

Best Case

Average Case

Worst Case

Example

Traversing

O(n)

O(n)

O(n)

Reading All Contacts

Searching

O(1) (Hash)

O(log n)

O(n)

Name Search

Insertion

O(1)

O(log n)

O(n)

Add Record

Deletion

O(1)

O(log n)

O(n)

Delete File

Sorting

O(n log n)

O(n log n)

O(n²)

Price Sorting

Merging

O(n + m)

O(n + m)

O(n + m)

Combine Data

Updating

O(1)

O(1)

O(n)

Change Value

Why Cost Estimation is Important
(cost estimation क्यों ज़रूरी है)

  1. Performance Optimization – जैसे Flipkart को हर Search के लिए Fast Result चाहिए।
  2. Better Memory Utilization – Low RAM वाले Systems में Efficient Algorithms जरूरी हैं।
  3. Scalability – लाखों यूज़र के Data को Handle करने में Cost Estimation से Planning होती है।
  4. Budget Planning (Cloud Cost) – AWS/Azure पर Cost Execution Time और Memory से तय होती है।

Real-Life Applications Example :

Application

Used Data Structure

Why

IRCTC

Queue, Tree

Ticket Scheduling

Paytm

Hash Map, Array

Fast Transactions

Google Search

Graph, Trie

Word Suggestions

ISRO

Matrix, Linked List

Data Transmission

Flipkart

Array, Heap

Sorting & Filtering

Advantages (लाभ)

  • Efficient Data Management (डेटा का कुशल प्रबंधन) : Data Structure से हम Data को इस तरह से Store करते हैं कि उसे Access, Update या Delete करना आसान होता है।
  • Faster Execution (तेज़ Execution Speed) : सही Structure चुनने से Algorithm की Speed बढ़ जाती है।
  • Reusability (पुनः उपयोग की क्षमता) : एक बार बना हुआ Structure (जैसे Stack, Queue) को अलग-अलग Programs में Reuse किया जा सकता है।
  • Memory Optimization (मेमोरी का बेहतर उपयोग) : Data Structures Memory को Dynamic रूप से Allocate करते हैं, जिससे Waste कम होता है।
  • Easy Data Processing (डेटा प्रोसेसिंग आसान) : Sorting, Searching, Updating आदि Operations को जल्दी किया जा सकता है।
  • Scalability (विस्तार क्षमता) : जब Data की मात्रा बढ़ती है, तो Structure के जरिए System को Scale करना आसान होता है।

Disadvantages (हानि)

  • Complex Implementation (जटिल संरचना) : कुछ Structures (जैसे Tree, Graph) को Implement करना मुश्किल होता है। इन्हें समझने के लिए Advanced Programming Knowledge चाहिए।
  • High Memory Consumption (अधिक मेमोरी उपयोग) : Pointer-Based Structures जैसे Linked List या Tree में Extra Memory लगती है (Pointer Storage के लिए)।
  • Debugging Difficulty (त्रुटि ढूंढना कठिन) : Data Link या Node Connection में गलती होने पर Program Crash या Infinite Loop की समस्या आ सकती है।
  • Time-Consuming Operations (समय लेने वाले कार्य) : कुछ Operations जैसे Sorting या Searching Unoptimized Structures में बहुत Slow हो सकते हैं (O(n²) तक)।
  • Dependency on Correct Choice (सही Structure का चयन ज़रूरी) : अगर Programmer ने गलत Structure चुना तो Performance गिर जाती है।
error: Content is protected !!