This website works better with JavaScript.
Home
Explore
Help
Sign In
jrtechs
/
jrtechs-RandomScripts
mirror of
https://github.com/jrtechs/RandomScripts.git
Watch
1
Star
0
Fork
0
Code
Issues
0
Releases
0
Wiki
Activity
Browse Source
Searching_Algo
pull/7/head
kishan_svt
6 years ago
parent
913d745e2a
commit
f787bd69bb
2 changed files
with
18 additions
and
0 deletions
Unified View
Diff Options
Show Stats
Download Patch File
Download Diff File
+12
-0
searching_algo/binary_search.py
+6
-0
searching_algo/linera_search.py
+ 12
- 0
searching_algo/binary_search.py
View File
@ -0,0 +1,12 @@
def
binary_search
(
arr
,
element
)
:
lower
=
0
upper
=
len
(
arr
)
-
1
while
(
lower
<
upper
)
:
mid
=
(
lower
+
(
upper
-
1
)
)
/
/
2
if
arr
[
mid
]
>
element
:
upper
=
mid
-
1
elif
arr
[
mid
]
<
element
:
lower
=
mid
+
1
else
:
return
True
return
False
+ 6
- 0
searching_algo/linera_search.py
View File
@ -0,0 +1,6 @@
def
linear_search
(
arr
,
element
)
:
for
i
in
arr
:
if
i
==
element
:
return
True
return
False
Write
Preview
Loading…
Cancel
Save