Do right-to-left language natives traverse trees in a different order than left-to-right language natives?

49 views Asked by At

In America every resource I've ever seen describes in-order traversal of a tree as "left, parent, right". Obviously there's nothing technically requiring that left take precedence over right, it's just a standard. Presumably this is because we read from left to right. Some languages in the world are read from right to left. Do programmers in cultures whose primary language is right-to-left still implement traversals from left to right?

1

There are 1 answers

0
Aboodz On

Here is the answer from a native Arabic speaker. The answer is it doesn't matter. Simply, because the in-order traverse is not really "left, parent, right". The 'correct' in-order traverse is "first child, parent, second child". Look when we change the node structure to this:

struct Node {
   Node firstChild; // used to be left
   Node secondChild; // used to be right
   Object value
}

The in-order traverse code wont break. This means You can draw/imagine it upside-down, right-to-left, straight-line... it's all up to you. Books choose to go for 'left' and 'right' because it is easier to teach.