Having the ability to add devices to the tree, it's even more important to retrieve them again. Just like the skip list in the previous chapter, this retrieval ideally runs in O(log n) time, meaning that the majority of elements are going to be skipped when searching.
Consequently, if the tree is skewed in one direction, the performance approaches O(n) and more elements are looked at, thereby making the search slower. Since a skewed tree is more like a list, the recursive insert algorithm can overflow the stack quickly thanks to the high number of "levels" with only a single item. Otherwise, the recursive algorithm is only called as many times as the tree's height, a considerably lower number in a balanced tree. The algorithm itself resembles the previously shown insert algorithm:
pub fn find(&self, numerical_id: u64) -> Option<IoTDevice> {
self.find_r(&self.root, numerical_id)
}
fn find_r(&self, node: &Tree, numerical_id...