Implement NFA Algorithm