An Optimal Algorithm To Generate Tilings