A five year old can do algebra. They can if they are one of those VERY rare children. By rare children I mean their brains can process work faster than others making them able to understand it yet being so young. Also maybe because they had learned quickly they had found a algebra book and started to self teach themselves how to do that. Because if a child has a strong mind and can grasp things and learn for themselves they can learn it from looking at complete problems. Then solve them. I have seen kids be able to do math like this at a young age because they were quick at grasping the information. Also it could be that they had copied a basic formula for algebra off of a website or math book and just put their numbers in and started solving it like that. Also it could just be that they had learned it form a parent or older sibling because they were smart enough they were able to already be learning. Finally it could just be that they are a mathematical genius and were able to complete things like that themselves.