edited recursive algo, added linkedlist algo