Function algos::search::exponential [−][src]
pub fn exponential<T: Ord>(a: &[T], x: &T) -> Result<usize, usize>
Exponential Search: Search for the value 'x' in an array.
Returns Err
holding the leftmost term if 'x' not found.
Obs.: Variation of binary search.
Case | Time complexity | Space complexity |
---|---|---|
Best: | Ω(1) | |
Avrg: | θ(log(n)) | |
Worst: | O(log(n)) | O(1) |
Example
use algos::search; let v = [1, 3, 4, 8, 11, 17, 23]; let find = search::exponential(&v, &11); assert_eq!(find, Ok(4)); let find2 = search::exponential(&v, &19); assert_eq!(find2, Err(6));