created a recursive searching algorithm