Dennis Deems wrote:Jeff, it is unclear to me how, using your method, converting the array to a tree will result in the same tree structure I started with.
Dennis Deems wrote:Jeff, it is unclear to me how, using your method, converting the array to a tree will result in the same tree structure I started with.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Dennis Deems wrote:Jeff, it is unclear to me how, using your method, converting the array to a tree will result in the same tree structure I started with.
Winston Gutkowski wrote:It might well not, and that may indeed be what you want.
Dennis Deems wrote:
Dennis Deems wrote:Jeff, it is unclear to me how, using your method, converting the array to a tree will result in the same tree structure I started with.
Winston Gutkowski wrote:It might well not, and that may indeed be what you want.
If I don't care what the result is, I'm not sure why I need an algorithm.
Jeff Verdegan wrote:
Dennis Deems wrote:Jeff, it is unclear to me how, using your method, converting the array to a tree will result in the same tree structure I started with.
That depends on the nature of the tree. Since the question is quite vague, with no details about the tree other than that it is n-ary, it's impossible to be very specific.If the tree behaves like a List, where iteration order matches insertion order, or if the tree behaves like a SortedSet, where iteration order follows sorting rules, then you'll get back what you started with. If neither of these are true, then it's impossible to do what the OP asks without more details about how elements will be added to and iterated over in the specific tree in question.
Dorothy Taylor wrote:So obviously the problem is convert the n-ary tree to an array. So if the root node is n, then left child is 2n+1 and right is 2n+2. That is clear,
however, it will leave some empty values in the array. Hence this solution is not space efficient.
So my question is that is Jeff's solution the best that can be done in this case, or is there a better way out?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Dorothy Taylor wrote:If it was as simple as Jeff's solution suggests, I wouldn't have posted in this forum. So obviously the problem is convert the n-ary tree to an array.
So if the root node is n, then left child is 2n+1 and right is 2n+2. That is clear, however, it will leave some empty values in the array. Hence this solution is not space efficient.
Again, suppose we devise a space efficient algorithm in which there are no empty array elements. then how do we get back the tree from this array?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |