Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

def intpolsearch(values,x ):
idx0 = 0
idxn = (len(values) - 1)

while idx0 <= idxn and x >= values[idx0] and x <= values[idxn]:

# Find the mid point
mid = idx0 +\
int(((float(idxn - idx0)/( values[idxn] - values[idx0]))
* ( x - values[idx0])))

# Compare the value at mid point with search value
if values[mid] == x:
return "Found "+str(x)+" at index "+str(mid)

if values[mid] < x:
idx0 = mid + 1
return "Searched element not in the list"


l = [2, 6, 11, 19, 27, 31, 45, 121]
print(intpolsearch(l, 2))