Honestly, there is no need to by heart any algorithm. Certainly, you must know them but, its OK if you forget some. The important part is to know data structures and given a question i.e. now you have to write an algorithm, you must, exactly know, which is the most efficient data structure for this problem. Once you solve the problem you can verify your algorithm (for complexity analysis) with an existing solution.