what is searching algorithm in data structure
searching algorithm in data structure:–
जिस प्रकार हम किसी school मे किसी student का record उसके roll number के द्वारा ढूंद्ते है उसी प्रकार data structure मे key के द्वारा हम key की सारी information निकाल सकते है ।
types of searching algorithms in Hindi
searching दो प्रकार की होती है
- Linear Searching Algorithm
- Binary Searching Algorithm
Linear Searching Algorithm:-
इस searching मे एक time मे एक record मे जाया जाता है । जब तक की record नहीं मिल जाए । इस linear search algorithm की complexity (n) = n/2 है जहां n numbers of record है ।
Algorithm:-
हमरे पास एक linear array DATA है जिसमे N element है हमने एक record ढूँढना है जिसका name ITEM है ITEM की LOC(location) search करनी है ।
जहाँ K= search करना है ।
1. [ initialization]
set K= 1 and LOC=0
2. repeat step 3 & 4 while LOC = 0 K<= N
3. IF ITEM = DATA 1[K] then set LOC=K
4. set K= K+1 (increase counter )
( end of step 2 loop)
[ successful]
5. if LOC =0 (ITEM is not in array DATA)
else write [ ITEM is found]
( end of if loop )
6. Exit
Algorithm + Data structure = programs
Binary Searching Algorithm:-
binary search मे list का short होना जरूरी है ।
EX. DATA, LB, UB, ITEM, LOC
यह DATA एक short array हिय जिसमे LB(lower bound) ओर UB( upper bound) है ITEM वह DATA है जिसको search करना है यह Algorithm item की location find करेगी।
Algorithm:-
1. [Initialization]
set BEG= LB , END= UB and
MID=(BIG+END/2)
2. repeat step 3&4 while BEG <= END and
DATA (MID) ≠ ITEM
3. IF ITEM < DATA (MID)
set END = MID-1
else
set BEG = MID+1
end IF
4. set MID = BEG + END/2
(end of step 2 loop )
5. if DATA [ MID] =ITEM
then
set LOC=MID
else set LOC= NULL
(end if loop)
6. Exit