Added datastructure and algorithm