Updating algorithms to use pointers and memory allocation.