Abstract
Binary Search is one of my favourite searchin algorithms, it is quick and efficient most of the times to search, given a sorted array.
This is an implementation of this algorithm in Rust. This post marks the start of my Rust learning journey. Implementing this algorithm is a must and this allows me to learn the Rust syntax given a familiar algorithm.
In this implementation, a vector is used instead of an array, this allows for dynamic memory allocation of a given list of sorted numbers.
Code
|
|
Output:
|
|
Similar to the previous implementation of Binary Search, I used the right shift >> 1
to do the division by 2 to get the mid
value, followed by the iterative version of the comparison.