Inorder tree traversal: Which definition is correct?

前端 未结 14 1341
轮回少年
轮回少年 2020-12-24 03:42

I have the following text from an academic course I took a while ago about inorder traversal (they also call it pancaking) of a binary tree (not BST):

14条回答
  •  抹茶落季
    2020-12-24 04:26

    Both definitions give the same result. Don't be fooled by the letters in the first example - look at the numbers along the path. The second example does use letters to denote the path - perhaps that is what is throwing you off.

    For example, in your example order showing how you thought the second tree would be traversed using the algorithm of the first one, you place "D" after "B" but you shouldn't because there is still a left-hand child node of D available (that's why the first item says "the order in which this line passes underneath them."

提交回复
热议问题