Skip to content

Commit 6564f8b

Browse files
Merge pull request #4 from Nitin-Pilkhwal/feature/add-sequential-search-algorithm
Create sequentialsearch.py
2 parents 76fc83c + 11521eb commit 6564f8b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import logging
2+
3+
def index_sequential_search(arr, value, jump):
4+
try:
5+
n = len(arr)
6+
i = 0
7+
while i < n:
8+
if arr[i] == value:
9+
return i
10+
i += jump
11+
if i >= n or arr[i] > value:
12+
break
13+
for j in range(max(0, i-jump+1), min(n, i+1)):
14+
if arr[j] == value:
15+
return j
16+
return -1
17+
except Exception as e:
18+
logging.exception("An error occurred during index sequential search: %s", e)
19+
return "An error occurred during index sequential search: {}".format(str(e))

0 commit comments

Comments
 (0)