Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78cd0e1

Browse filesBrowse files
authored
The Jump Search
1 parent 722817f commit 78cd0e1
Copy full SHA for 78cd0e1

File tree

Expand file treeCollapse file tree

1 file changed

+20
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-0
lines changed

‎searches/jump_search.py

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import math
2+
3+
def jumoSearch (listA, theGoalValue):
4+
length = len(listA)
5+
jump = int(math.sqrt(length))
6+
left, right = 0, 0
7+
while length > left && theGoalValue >= listA[left]:
8+
right = min(length - 1, left + jump)
9+
if listA[left] <= theGoalValue and listA[right] >= theGoalValue:
10+
break
11+
left += jump;
12+
if left >= length or listA[left] > theGoalValue:
13+
return -1
14+
right = min(length - 1, right)
15+
i = left
16+
while i <= right and listA[i] <= theGoalValue:
17+
if listA[i] == theGoalValue:
18+
return i
19+
i += 1
20+
return -1

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.