I’m trying to convert a list-based tree implementation into an array-based implementation with the parent at the ith index, left child at 2ith index and right child at 2i+1th index. for some reason the conversion results in loss of data for trees with bigger number of nodes. I’d like to know what all boundary conditions i need to check for while implementing this. Thanks!
I’m trying to convert a list-based tree implementation into an array-based implementation with the
Share
Assuming your language uses zero-based indices the children of node
igo into2i + 1and2i + 2not2iand2i + 1. The later works for one-based indices.