Recursive implementation using vectors