JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Array operation : Sorting or Searching in hindi in c computer language सोर्टिंग तथा सेरचिंग इन हिंदी

सोर्टिंग तथा सेरचिंग इन हिंदी Array operation : Sorting or Searching in hindi in c computer language :-
Array मे दो operation मुख्य है |
(1) Sorting :
Sorting का मतलब है array के values को किसी पैटर्न (बढ़ते क्रम और घटते क्रम  ) मे व्यस्थित करना है |ये दो प्रकार का होता है |
(1.i) Selection Sort :
Seletion sort, selection sort algorithm को फॉलो करता है |
अगर प्रोग्रामर ascending पैटर्न मे data values को arrang करता है तब selection sort algorithm,सबसे छोटो values को find करके  इसे array के starting position पर assign कर देता है |
इसमें दो array होती है (i) First Sub array जो पहले से sort होती है (ii) Second  sub array जिसमे सर्चिंग होती है |उदहारण के लिए :
array[]=12,23,10,34,56,45

First searching मे,इसमें first element का compare बाकि के element के साथ होता है अगर condition सही होने पर first element और compare element मे swaping होती है |
New element का comparison आगे के element साथ होता है condition सही होने पर swaping होती है नहीं तो उस element की  first position पर जगह fixed हो जाती है | सबसे छोटा element 10 है जो array की first position पर आ जाता है |
array[]=10,   23,12,34,56,45 // Blod value unsorted sub array है|

Second searching मे, first position को छोड़ कर पूरी comparison दुबारा होता है |और 12 सबसे छोटा element है जो unsorted sub array के first position पर आ जाती है |
array[]=10,12,    23,34,56,45

Third searching मे ,  23 और 34 स्वत ही unsorted sub array के first दो place पर है |केवल 45 और
56 मे swqaping हो जाती है |

array[]=10,12,23,34,45,56

C Program :
#include <stdio.h>
#include<conio.h>
void main()
{
int array[6]={12,23,10,34,56,45};
int n=6;
int i,j,min;
for(i=0;i<n-1;i++)
{
min=i;
for(j=i+1;j<n;j++)
{
if(array[min]>array[j])
{
int temp ;
temp=array[j];
array[j]=array[min];
array[min]=temp;
}
}
for(i=0;i<n;i++)
{
printf(“%d”,aray[i]);
}
getch();
}

2.Bubble Sorting:
Bubble sorting का मुख्य काम होता है किसी array की values को किसी पैटर्न मे arrange करना |
उइदहरन के लिए :
array[]=12,34,22,35,45,31,23
first Pass मे :

(i)इसमें पहले दो position के values का comparsion होता है और condition array[first position] < array[second position] सही होने पर swaping होती  है |
array[]=34,12,22,35,45,31,23
(ii)फिर पहली position को छोड़ कर ,दूसरी और तीसरी position के values का comparsion होता है ,condition array[second position <  array[third position] सही होने पर swaping होती है |
array[]=34,22,12,35,45,31,23
(iii) तीसरी और  चोथी position के values का comparsion होता है ,condition सही होने पर swaping होती है |
array[]=34,22,35,12,45,31,23
(iii)त्याही process चलती रहेगी |first pass के बाद :-
array[]=34,22,35,45,31,23,12
Second Pass मे :
(i)इसमें पहले दो position के values का comparsion होता है और condition array[first position] < array[second position] सही होने पर swaping होती  है |इस step मे कोई swaping नहीं होगी क्योकि( 34<22) false है |
array[]=34,22,35,45,31,23,12
(ii)फिर पहली position को छोड़ कर ,दूसरी और तीसरी position के values का comparsion होता है ,condition array[second position < array[third position] सही होने पर swaping होती है |

array[]=34,35,22,45,31,23,12

ये प्रोसेस जब तक सभी value आपस मे compare नहीं हो जाती जन तक होती रहेगी | Second Pass के end मे array[]=34,35,45,31,23,22,12

Third Pass के end मे array[]=35,45,34,31,23,22,12

Fourth pass के end मे array[]=45,35,34,31,23,22,12

इस sorting मे pass की सख्या n-1 होती है |

Program for Bubble Sorting:

#include <stdio.h>
#include<conio.h>
void main()
{
int array[6]={12,34,22,35,45,31,23};
int n=6;
int i,j,min;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n-i-1;j++) // j<n-i-1 besause last digit already in place
{
if(array[j]>array[j+1])
{
int temp ;
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
for(i=0;i<n;i++)
{
printf(“%d”,aray[i]);
}
getch();
}

2.Searching :

Array मे किसी data को search करने के लिए दो searching techniques का use किया जता है |

2.i) Linear Searching
इसमें values जिसे search करना है उसे  array के सभी values] मे compare किया जाता है |इसकी time complexity O(n) होती है |इसलिए इसे practical मे use बहुत कम ही किया जाता है |
Programme For linear Searching :
#include<conio.h>
#include<stdio.h>
void main()
{
int array[6]={12,34,22,35,45,31,23};
int search;
printf(“Enter Your data that You want to Search”);
scanf(“%d”,&search);
for(i=0;i<n;i++)
{
if (search==a[i])
{
printf(“Your data is in list.”);
printf(“Index is =%d”,i);
break;
}
}
if(n==i)
{
printf(“Sorry,Your data is not in array.”)
}
}
आउटपुट होगा :
Enter Your data that You want to Search 12
Your data is in list.Index is 0.

(2.ii)Binary Searching
ये searching sorted array मे ही होती है |इसमें array को दो parts मे डिवाइड कर दिया जाता है |right और left|अगर searched data का comparesion middle item से किया जाता है :-
अगर middle value औरsearched data same है तो search कम्पलीट हो जाता है |
अगर middle value< searched data , search, left position array  मे होती है |
अगर middle value > searched data , search, right position array  मे होती है |
इसकी time complexity linear searching से half होती है |

Binary search का  program function की सहायता से function article मे है |
Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now