Operations on Data Structures in Hindi

Srajan
⏰ 7 min read

सिलेबस के अनुसार DATA STRUCTURES के सभी टॉपिक यहाँ देखें — बिल्कुल फ्री

Table of Contents

Operations on Data Structures in Hindi – Data Structure Operations क्या हैं?

Endless Horse – Find End? Play Game {{D1}}
  • Data Structure Operations वे basic actions हैं जिनसे stored data को access, search, insert, delete, sort और modify किया जाता है।
  • इन operations की मदद से data को efficiently manage और process किया जाता है।
  • Main Operations हैं: Traversing, Searching, Insertion, Deletion, Sorting, Merging और Updating।
  • हर operation की implementation और Time Complexity, Array, Linked List, Stack, Queue या Tree जैसे Data Structure पर depend करती है।
  • Operations की efficiency को Time Complexity और Space Complexity से measure किया जाता है।
  • उदाहरण के लिए, Array में index से access O(1) होता है, जबकि middle में insertion या deletion के लिए O(n) shifting लग सकती है।

Example of Operations on Data Structures (उदाहरण)

Example: Array [10, 20, 30, 40] में सभी values print करना Traversing, 30 को find करना Searching, 25 add करना Insertion, 20 remove करना Deletion और 30 को 35 करना Updating है।

Traversing in Data Structure in Hindi – Traversing क्या है?

Traversing एक operation है जिसमें Data Structure के elements को एक-एक करके access और process किया जाता है। इसका उपयोग display, counting, sum और data processing में होता है। Array Traversal में सामान्यतः हर element को एक बार visit किया जाता है, इसलिए इसकी Time Complexity O(n) होती है।

{{D2}}
  1. Start: Array के index 0 से traversal शुरू होता है।
  2. Visit: Current element को access करके required processing की जाती है।
  3. Move: Next index पर move किया जाता है।
  4. Stop: Index n − 1 process होने पर traversal complete होता है।

Array में यह काम loop और index से होता है। Linked list में head से चलकर NULL आने तक, और tree में inorder, preorder या postorder क्रम से traversal किया जाता है, जिसके बारे में Tree Traversal और BFS and DFS में विस्तार से पढ़ सकते हैं।

#include <stdio.h>

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

    for (i = 0; i < 5; i++) {
        printf("%d ", arr[i]);      // हर element को visit करना
        sum = sum + arr[i];
    }
    printf("\nSum = %d\n", sum);
    return 0;
}

Output:

10 20 30 40 50
Sum = 150

Searching in Data Structure in Hindi – Searching क्या है?

Searching वह operation है जिसमें किसी Data Structure में दी गई Key या Value को find किया जाता है। Key मिलने पर उसका index या reference return किया जा सकता है। Searching के common methods Linear Search और Binary Search हैं।

Linear Search में elements को शुरुआत से एक-एक करके Key से compare किया जाता है। इसमें sorted data की जरूरत नहीं होती। Best Case O(1) और Worst Case O(n) है।

{{D3}}

Binary Search एक divide-and-conquer searching algorithm है। यह sorted array में middle element से Key compare करके search range को आधा करता है। इसकी Worst Case Time Complexity O(log n) होती है।

{{D4}}

3. Complete Program and Output

#include <stdio.h>

int linearSearch(int arr[], int n, int key) {
    int i;
    for (i = 0; i < n; i++) {
        if (arr[i] == key) return i;
    }
    return -1;                      // key नहीं मिली
}

int binarySearch(int arr[], int n, int key) {
    int low = 0, high = n - 1, mid;
    while (low <= high) {
        mid = (low + high) / 2;
        if (arr[mid] == key) return mid;
        else if (key > arr[mid]) low = mid + 1;
        else high = mid - 1;
    }
    return -1;
}

int main() {
    int a[5] = {10, 20, 30, 40, 50};
    int b[7] = {10, 20, 30, 40, 50, 60, 70};

    printf("Linear Search : index %d\n", linearSearch(a, 5, 40));
    printf("Binary Search : index %d\n", binarySearch(b, 7, 60));
    return 0;
}

Output:

Linear Search : index 3
Binary Search : index 5

Insertion in Data Structure in Hindi – Insertion क्या है?

Insertion का अर्थ Data Structure में नया element add करना है। Array के beginning या middle में insertion के लिए elements को right shift करना पड़ सकता है। Array में पर्याप्त capacity न होने पर insertion संभव नहीं होता।

{{D5}}

1. Insertion Algorithm

  1. Overflow Check: पहले check करें कि Array में free capacity उपलब्ध है।
  2. Shifting: Insertion index से आगे के elements को एक position right shift करें।
  3. Placing: Required index पर नया element store करें।
  4. Size Update: Logical size n को 1 बढ़ाएँ।

2. Insertion की Positions

  1. At Beginning: सभी n elements एक कदम दाएँ खिसकते हैं, इसलिए Time Complexity O(n) रहती है।
  2. At Middle: position के बाद के सभी elements खिसकते हैं, और औसतन यह भी O(n) है।
  3. At End: किसी element को खिसकाना नहीं पड़ता, इसलिए जगह होने पर यह O(1) में हो जाता है।

Linked List में insertion के लिए nodes के links update किए जाते हैं। यदि insertion position का node पहले से उपलब्ध हो, तो link changes O(1) में किए जा सकते हैं; position search करने में O(n) लग सकता है।

3. Complete Program and Output

#include <stdio.h>

int main() {
    int arr[10] = {10, 20, 30, 40, 50};
    int n = 5, pos = 2, value = 25, i;     // pos = index 2

    for (i = n - 1; i >= pos; i--) {
        arr[i + 1] = arr[i];               // दाएँ खिसकाना
    }
    arr[pos] = value;
    n++;

    for (i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}

Output:

10 20 25 30 40 50

Deletion in Data Structure in Hindi – Deletion क्या है?

Deletion वह operation है जिसमें Data Structure से existing element remove किया जाता है। Array के beginning या middle से delete करने पर remaining elements को left shift करना पड़ता है। Empty structure से deletion का प्रयास Underflow कहलाता है।

{{D6}}

1. Deletion Algorithm

  1. Underflow Check: Deletion से पहले check करें कि Array empty न हो।
  2. Locate: Delete किए जाने वाले element का valid index identify करें।
  3. Shifting: Deleted index के बाद वाले elements को एक position left shift करें।
  4. Size Update: Logical size n को 1 घटाएँ।

2. Deletion की Positions

  1. From Beginning: बाकी सभी elements एक कदम बाएँ आते हैं, इसलिए Time Complexity O(n) है।
  2. From Middle: position के बाद वाले elements खिसकते हैं, और औसतन यह O(n) है।
  3. From End: खिसकाने की ज़रूरत नहीं पड़ती, सिर्फ n घटाना होता है, इसलिए यह O(1) है।

Linked List में deletion के लिए संबंधित links update किए जाते हैं और dynamically allocated node की memory release की जाती है। Node को locate करने में अलग समय लग सकता है।

3. Complete Program and Output

#include <stdio.h>

int main() {
    int arr[10] = {10, 20, 30, 40, 50};
    int n = 5, pos = 2, i;                 // index 2 का element हटाना है

    for (i = pos; i < n - 1; i++) {
        arr[i] = arr[i + 1];               // बाएँ खिसकाना
    }
    n--;

    for (i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}

Output:

10 20 40 50

Sorting in Data Structure in Hindi – Sorting क्या है?

Sorting में elements को Ascending या Descending Order में arrange किया जाता है। यह Searching, reporting और organized data processing में उपयोगी है। Common Sorting Algorithms में Bubble Sort, Selection Sort, Insertion Sort, Merge Sort और Quick Sort शामिल हैं।

1. Bubble Sort Working

Bubble Sort में adjacent elements compare किए जाते हैं। गलत order होने पर उन्हें swap किया जाता है। हर pass के बाद सबसे बड़ा unsorted element अपने सही स्थान पर पहुँचता है। Standard Bubble Sort की Worst Case Time Complexity O(n²) है।

{{D7}}

2. Common Sorting Algorithms

Algorithm मूल विचार Worst Case Time Complexity
Bubble Sort पास-पास के elements की अदला-बदली O(n²)
Selection Sort हर बार सबसे छोटा element चुनकर आगे रखना O(n²)
Insertion Sort हर element को पहले से sorted हिस्से में सही जगह डालना O(n²)
Merge Sort Array को आधा-आधा बाँटकर sort करना और फिर merge करना O(n log n)
Quick Sort Pivot चुनकर छोटे और बड़े elements के दो हिस्से करना O(n²), औसतन O(n log n)

3. Complete Program and Output

#include <stdio.h>

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

    for (i = 0; i < n - 1; i++) {             // passes
        for (j = 0; j < n - 1 - i; j++) {
            if (arr[j] > arr[j + 1]) {        // गलत क्रम हो तो swap
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }

    for (i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}

Output:

10 20 30 40 50

Merging in Data Structure in Hindi – Merging क्या है?

Merging में दो या अधिक Data Structures के elements को combine किया जाता है। दो sorted arrays को sorted order में merge करने के लिए दोनों के current elements compare किए जाते हैं। इस तरीके की Time Complexity O(m + n) होती है।

{{D8}}

1. Merging Algorithm

  1. Two Pointers: दोनों sorted arrays के लिए अलग pointers initialize करें।
  2. Compare: Smaller current element को output में copy करके संबंधित pointer आगे बढ़ाएँ।
  3. Repeat: किसी एक array के समाप्त होने तक comparison repeat करें।
  4. Copy Remaining: Remaining elements को output array में copy करें।

यदि पहले array में m और दूसरे में n elements हैं, तो sorted merging में कुल m + n elements process होते हैं। नया output array बनाने पर Auxiliary Space O(m + n) लगता है।

2. Complete Program and Output

#include <stdio.h>

int main() {
    int a[3] = {10, 30, 50};
    int b[3] = {20, 40, 60};
    int c[6];
    int i = 0, j = 0, k = 0;

    while (i < 3 && j < 3) {
        if (a[i] < b[j]) c[k++] = a[i++];
        else             c[k++] = b[j++];
    }
    while (i < 3) c[k++] = a[i++];       // a के बचे elements
    while (j < 3) c[k++] = b[j++];       // b के बचे elements

    for (i = 0; i < 6; i++) {
        printf("%d ", c[i]);
    }
    return 0;
}

Output:

10 20 30 40 50 60

Updating in Data Structure in Hindi – Updating क्या है?

Updating में Data Structure के existing element की value modify की जाती है। Array में index ज्ञात होने पर update O(1) में होता है। यदि element को पहले search करना पड़े, तो कुल time searching method पर निर्भर करता है।

{{D9}}

1. Update by Index

Array में valid index ज्ञात होने पर element को सीधे arr[i] = newValue; से update किया जा सकता है। Direct Access के कारण Time Complexity O(1) होती है।

2. Update by Value

जब index ज्ञात नहीं होता, तब पहले element को search करना पड़ता है। Unsorted Array में Linear Search के साथ update की Worst Case Time Complexity O(n) होती है।

3. Complete Program and Output

#include <stdio.h>

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

    arr[2] = 35;                        // index से update

    for (i = 0; i < 5; i++) {           // value से update: पहले ढूँढो
        if (arr[i] == 50) {
            arr[i] = 55;
            break;
        }
    }

    for (i = 0; i < 5; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}

Output:

10 20 35 40 55

Time Complexity of Operations in Hindi – ऑपरेशन्स की टाइम कॉम्प्लेक्सिटी

Operation Array में Time Complexity वजह
Traversing O(n) हर element एक बार visit होता है
Searching Linear: O(n), Binary: O(log n) Binary Search हर कदम पर आधे elements हटा देता है, पर sorted array चाहिए
Insertion शुरू या बीच में O(n), अंत में O(1) बीच में जगह बनाने के लिए elements दाएँ खिसकते हैं
Deletion शुरू या बीच से O(n), अंत से O(1) हटाने के बाद elements बाएँ खिसकते हैं
Sorting O(n log n) से O(n²) तक Algorithm के चुनाव पर निर्भर
Merging O(m + n) दोनों arrays के हर element को एक बार रखा जाता है
Updating Index से O(1), value से O(n) Value से update में पहले search करना पड़ता है

FAQs

Data structure में रखे डाटा पर की जाने वाली क्रियाओं को ऑपरेशन्स कहते हैं। इनमें Traversing, Searching, Insertion, Deletion, Sorting, Merging और Updating सबसे आम हैं।
Traversing में data structure के हर element को क्रम से ठीक एक बार visit किया जाता है। Array में यह index 0 से n − 1 तक loop चलाकर किया जाता है।
Searching में किसी दी गई key को data structure में ढूँढा जाता है और मिलने पर उसकी position बताई जाती है। इसके दो मुख्य तरीके Linear Search और Binary Search हैं।
Linear Search हर element की key से तुलना करता है, unsorted array पर भी चलता है और इसकी complexity O(n) है। Binary Search सिर्फ sorted array पर चलता है और हर कदम पर आधे elements हटाकर O(log n) में काम करता है।
Insertion में data structure में नया element जोड़ा जाता है। Array में बीच में जोड़ने के लिए बाद के elements को दाएँ खिसकाना पड़ता है, और जगह न होने पर Overflow की स्थिति आती है।
Deletion में किसी मौजूदा element को हटाया जाता है। Array में उसके बाद के elements को बाएँ खिसकाकर जगह भरी जाती है, और खाली structure से हटाने की कोशिश Underflow कहलाती है।
Sorting में elements को ascending या descending क्रम में लगाया जाता है। Bubble, Selection, Insertion, Merge और Quick Sort इसके आम algorithms हैं।
Merging में दो sorted arrays या lists को मिलाकर एक नया sorted array बनाया जाता है। इसकी Time Complexity O(m + n) है और यही Merge Sort का आधार है।
Updating में मौजूद element की value बदली जाती है, जबकि elements की संख्या और positions वही रहती हैं। Index पता हो तो यह O(1) में होता है, और value से update करने पर पहले search करना पड़ता है।
Array में Traversing O(n), Linear Search O(n), Binary Search O(log n), बीच में Insertion और Deletion O(n), Merging O(m + n) और index से Updating O(1) होती है। Sorting की complexity algorithm के हिसाब से O(n log n) से O(n²) तक रहती है।
Srajan

✍️ Srajan

SEO Executive | Content Research & Optimization | 1.5+ Years of Experience

•