Function algos::search::fibonacci[][src]

pub fn fibonacci<T: Ord>(a: &[T], x: &T) -> Result<usize, usize>

Fibinacci Search: Search for the value 'x' in an array. Returns the the last offset it passed if 'x' not find as Err.

This is based on binary search.

Time complexity Space complexity
Best: Ω(1)
Avrg: θ(log(n))
Worst: O(log(n)) O(1)

#Examples

use algos::search;

let v = [1, 3, 4, 8, 11, 17, 23];

let find = search::fibonacci(&v, &11);
assert_eq!(find, Ok(4));

let find2 = search::fibonacci(&v, &19);
assert_eq!(find2, Err(3));