Optmized Chuyuan's algorithm and create examples for IPython Notebook.