How to check an algorithm's space complexity?