FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/data-structures/binarySerach.py at master · AllAlgorithms/python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
AllAlgorithms
/
python
Public archive
Notifications
You must be signed in to change notification settings
Fork
170
Star
385
Code
Issues
1
Pull requests
19
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
data-structures
/
binarySerach.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (24 loc) · 758 Bytes
Breadcrumbs
python
/
data-structures
/
binarySerach.py
Copy path
File metadata and controls
25 lines (24 loc) · 758 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def
binSearch
(
a
,
x
,
low
,
high
):
#Return True if target is found in indicated portion of a Python list.
#The search only considers the portion from data[low] to data[high] inclusive.
if
low
>
high
:
return
False
# interval is empty; no match
else
:
mid
=
(
low
+
high
)
//
2
if
x
==
a
[
mid
]:
# found a match
return
True
elif
x
<
a
[
mid
]:
# recur on the portion left of the middle
return
binSearch
(
a
,
x
,
low
,
mid
-
1
)
else
:
# recur on the portion right of the middle
return
binSearch
(
a
,
x
,
mid
+
1
,
high
)
a
=
[
5
,
10
,
15
,
20
,
25
,
30
,
40
]
x
=
20
low
=
0
high
=
6
result
=
binSearch
(
a
,
x
,
low
,
high
)
if
result
:
print
(
"The value "
,
x
,
" Found"
)
else
:
print
(
"The value "
,
x
,
" Not found"
)
Back
|
FazBrowse Home
|
New Git URL