DSA Searching
DSA Searching
THpes
Intwanal Sear chn4
(). Eernal
a Linea easchiny
In near eAsCh eAch elementdan
array is ed O ne by one 3eq veqtally and
Lonpaed wih. L h a d e r e d elemes
ALgoiLn
1
Setiodex Q
Scan eaeh eement a y dne 0ar
33 1 math dccw75 hen n h e indax
5tep y
dHherUi3P 6et ndey in der +i _gora gkp2-
4. eit.
Ipv an ary
4dnnelemett d "data
F be se4rched
Lni ialise i 20 and
epea hrgh 3tep 3
i i<n byin(remehnq ne
1
d ACiACii_
b 0t
Prit d aa is nt ond
5earhln is
5 t.
b in4 SeTch
bina
we trs Lnpare he
Ley wih he tem nhe middie poihn he ary
he
he e'3 a a y
matth, we can
retn_ imme d aky. 1
he e is
e s han h e muddle key hen he
h
tem
ngtt_mus t ic in he wewr hal d he
aa 1 t e dhan Lhe tem sng t muse
iein h e ppe ha!? dg he a y . 0 we repeat
he pmce dire
on h e lwer
he ru4
a
&ppes) ha
an
iientk algniiy when
Uneg 6earch bt he amy ha
obe Snted bere ding na ry4 se4rh
Adwantagesi
in a 6earthin each Conpan4ion2
he ize d heseasch ae A is ve doced by
hal , it is24stest mehod
han
i nea %e4rdh,
BisadAargs
Binary 6e4rch requires hat he
tens he a 4 h nid be 6 ted
Binary earch Cadt be vsed whee
here are mhs insesions r delehns.
O Initalig 0 end n-1 and
mid(beyt end)/ n'nonber
nombey Q5ntt
5ted
elemeak in an
repea_ 6kps
3 dnd 4 whie (begiad
and. amid!a item|
1 tem< 4[mid
end: id 1
else
be mid t
6e mid
5
(heqa end )/2
aLmid7 = item
hen
hen set Loc mid 4 displ ay*
vawe is mnd al De Lecak on
else
dsplay he dan doesn't eis
eit
0 d 531
15L 0 3 318 u89 64 591 47
mid : 3
end :7
Hashinq
Di2rrt eaTcAng Teehn qves ee
binary n e r are based on_ampamons
teys (data. But hasbinq is an appmh
mini mize he no Conp4Aionsin de
nd he de sie
TE is hat 6eah teeini qve Dh eme
00 nett esaryLompaions 4e quind.
JocaHon he
Hee Lhe
C pi le
eiee the dt
Aesi ed ree_id in d e r
ingle atte
Hash +able
Hash -table s6mply
is 4ddbessed a a hash vnchon
Hash tb te is divi dedinto a no bvtbeks
and eash bucke has hmber s l 4ts 4eauh
l o t is Capable hoidiay ne elwd,
JocaHon SLot
Hash ab le.
Hash FonHon
The basic' i dea in haghing i s h e
tansmahon a beyinto Lhe muponddne
Jarahoo h e hash tble.Thi isdan
a hash nchn A hash nHon Lan be
d o l vS eLhid
his medhod treany- hash
onthon, we map Ley one
+ n g h e èmainde lQvided ded b m
.e HL) k md
Let Hash able
Insra+ Y5 333, 7
+hen,
3333
H333) 333 I = 3
10
HASH TA BLE
Aple
InsesS*. 1, 13
1 19Y 4
124
34 13y I7 956
3
44
foIdin4. Mhod
0ne he eaiet way +o Unput
he eq 15 o b e a he ey Into
bey he cesadd
hem et he hash 4d dreh
eaample Let has hasle size 6d
1234
46 50
0 4 is he hash Eey. And
a 34 in-hash table
25
+a6
Colliion m Ire. d a
d o l i i on That
,
3 occis the
Re has kna
pen ad d r e i na
Hashu wi
n e a r p ing
1adakt ,
D ble hAn4.
Sol 2 3
26 34
serk 6.
h (t, iJ h l e ) +iJ ma m
41
h 0) 8 mad 1l +0] mod
mdd 1l Y
L+07 mod i1
nne T C4] is easen
inseab 37
npokd
h(37,) 37 mod t! 1] mbd !
So
ia
dthe
p siny
meno UGes
hash nthon
Thi& d
6
Consi de he , 6 37, 59 ,1,
as h rble 11
mod m
it 3i]
h (E,i)-k mod mt
mod 1L1
. seAt
Li t 0 t] mod
mod
h (76,0) :(76 lo) m0d 11
0 tiis lae
he Eey 76 at
nest
TCi0] 15 ,
qval able
6es
hash ne he
Dnble A4hi ng mud m
(h () i h, (t))
h (,') Lhe pimuy/ aueilieny
hash
hash
a*
h)
d h,(E)
Conscer esthngha ays 7 , 37, 63, 1 5
h e hash +hle
U ng dble hashing
Con der dhe Pnany hash voion are h (k) L mod
h() mod j
nse 626
h(7) : 7 mod ii = 10
h6)= 7 mod 9
h(76,0)=(10 ox4) mod 1
h 6 , 0) = (9 +0x?) mod Y
nse 37
h (32) 9
hCa7)1
h (37,o 1
TCY nt e
0 h (37, 1) (+ iai)med *
!= 5
n 6rhed daty
Insest
8 19 /5 33 2
17, 1 6 o
a h a i npd ash rsIe. Let oS he hash abie
spp
Sl0- and -he kash
has vn ion be h (e) =k md
The ns al H
h e chainrd - hash able
S
h ( s ) s ms 5
5NVL|
nses
mod 9 i
h 2e) d& =
RZ7
13.
19 mod 9 !
C19) =
ehasi ng
The a (hanves d aserti en ilure whey Lah tahie
ash able 4 wn
5,u6,{2,10, 9,72
, 8 3 10, 3
hle) : (h'lR) + i) mid r
8
66
43
wnst 62
h'l)= med m 4
62 m0d 7
l
7t m0 d ewi ake nestdble
Aln n table is . 50
dable wjlh pr me ndmbe he nexs
n re han
is 3. 3
nvmkser t ditie i e 12
me e
asi wi be (akd i z 3 d a
asefrd ew
elemeals wii be
HE) mld 3.