Skip to content

Commit 915bd75

Browse files
authored
Merge pull request deutranium#93 from Hamzakam/exponential-search
Create readme.md
2 parents 07e9f7f + 3be6ef1 commit 915bd75

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# Exponential Search
3+
4+
- Exponential search allows for searching through a sorted, unbounded list for a specified input value.
5+
- Time Complexity:
6+
- Worst Case Complexity:_O_(log _i_)
7+
- Best Case Complexity:_O_(1)
8+
- Average Case Complexity:_O_(log _i_)
9+
- Worst Case Space Complexity:_O_(1)
10+
- Exponential Search will run in _O_(log _i_) time, where _i_ is the index of the element being searched for in the list, whereas binary search would run in _O_(log _n_) time, where _n_ is the number of elements in the list.
11+
- Works only on sorted lists.
12+
13+
### Logic
14+
15+
1. Find range where element is present
16+
2. Do Binary Search in above found range.
17+
3. Pseudo Code:
18+
19+
function exponentialSearch(arr, x, lo, hi):
20+
if arr[hi] >= x:
21+
return(binarySearch(arr, x, lo, hi + 1))
22+
else:
23+
return(exponentialSearch(arr, x, hi, hi * 2))
24+
25+
function binarySearch(arr, x, lo, hi):
26+
index = (lo + hi)/2
27+
if x = arr[index]
28+
return index
29+
else if x > arr[index]:
30+
return binarySearch(arr, x, index, hi)
31+
else:
32+
return binarySearch(arr, x, 0, index)
33+
34+
### Instruction for Running code:
35+
36+
- Python
37+
38+
```
39+
python3 exponentialSearch.py
40+
```

0 commit comments

Comments
 (0)