Recently I attended an interview and I was asked to serialize a given tree. As I was about to start, the interviewer asked about the approach to take. I replied, it's going to be preorder with some special char for null. He said, that will waste a lot of space -can you do that without storing extra chars? But all approach need extra space, I know a few :
- Inorder and preorder both rep.. but this needs 2n space upfront
- Level order .. but again this needs additional space
- Preoder with special char
But above approaches need additional space. He was adamant that we can do it without additional storage .. on asking what the approach could be .. he asked to google. Any clues? I have been googling and am not able to find any approach where null is not represented by special character.