When to use Preorder, Postorder, and Inorder Binary Search Tree Traversal strategies

前端 未结 5 1294
萌比男神i
萌比男神i 2020-12-12 08:47

I realized recently that while having used BST\'s plenty in my life, I\'ve never even contemplated using anything but Inorder traversal (while I am aware of and know how eas

5条回答
  •  时光说笑
    2020-12-12 09:19

    Pre- and post-order relate to top-down and bottom-up recursive algorithms, respectively. If you want to write a given recursive algorithm on binary trees in an iterative fashion, this is what you will essentially do.

    Observe furthermore that pre- and post-order sequences together completely specify the tree at hand, yielding a compact encoding (for sparse trees a least).

提交回复
热议问题