This algorithm correctly searches a tree and returns true if the searchValue is in the tree, I understand the base case, but I'm a little lost on the else
statement, I'm not understanding what the ||
does in this scenario, is it returning both of those or just one in certain cases?
func search(node: Node?, searchValue: Int) -> Bool {
if(node == nil){
return false
}
if(node?.value == searchValue){
return true
} else {
return search(node: node?.leftChild, searchValue: searchValue) || search(node: node?.rightChild, searchValue: searchValue)
}
}