See: Grokking Algorithms - An illustrated guide for programmers and other curious people by Aditya Y. Bhargava