Rust Programming Exercises: Binary Search
Channel: nyxtom 🏕
Date: 2022-04-17

In this video we will implement the classic binary search algorithm over a sorted collection of integers. We will implement several variations using the standard while loop with if/else conditions as well as one with the match control operator in Rust. Additionally, we'll take a look at the std::cmp::Ord trait and using generics to make our function more flexible.

*Note:* It's worth noting that the standard library contains a binary_search function that you can use already (however, we are implementing ours manually). https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search The result of this function will return a Result to indicate the found index or the index to insert at to maintain sort order.

↠ References:
Binary Search: https://en.wikipedia.org/wiki/Binary_search_algorithm
Match Control Flow: https://doc.rust-lang.org/book/ch06-02-match.html
Cmp: https://doc.rust-lang.org/std/cmp/trait.Ord.html#tymethod.cmp
Ord Trait: https://doc.rust-lang.org/std/cmp/trait.Ord.html
Generics: https://doc.rust-lang.org/book/ch10-00-generics.html

↠ Dotfiles: https://github.com/nyxtom/dotfiles
↠ Twitter: @nyxtom https://twitter.com/nyxtom
↠ Channel: https://www.youtube.com/c/nyxtom

Cheers! 🍻

🦀  #rust #rustlang #rustprogramming #exercises #leetcode #programming #algorithms