Re:Inverting Binary Trees Considered Harmful
by steego on Friday June 12, 2015 @12:30PM
(#9706907)
I'm still not entirely sure what that means. Does it mean you recursively swap left and right branches, or does it mean you create a new data structure where the bottom elements become the top elements?
[ Parent
| on HN ]
Re:Inverting Binary Trees Considered Harmful
by discardorama on Friday June 12, 2015 @01:31PM
(#9707333)
Apparently it means to swap the left and right subtrees. How's that "inversion"? I'd call it "flipping" or "mirroring" or something... If this is the case, then it's a trivial solution: invert(left_child); invert(right_child);
Re:Inverting Binary Trees Considered Harmful
by 59nadir on Saturday June 13, 2015 @10:35AM
(#9711114)
Or, if the structure is this:
struct node {
struct node *left_node;
struct node *right_node;
int val;
};
struct reversed_node {
struct reversed_node *right_node;
struct reversed_node *left_node;
int val;
};
No? You then just have a different mapping for the exact same data, no traversal needed.