algorithms from textbook