Jump to content

Preorder vs. Inorder vs. Postorder

- - - - -

  • Please log in to reply
1 reply to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
Okay, so I've implemented preorder, postorder, and inorder traversals of a binary tree in C. I've found that inorder traversal is best for sorting a previously sorted tree after adding or deleting a node, because it allows for an optimized bubble sort that only moves one element. What are the respective advantages of preorder and postorder traversals? Is there a tutorial on data structure optimization somewhere?
Programming is a journey, not a destination.

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP

Quote

What are the respective advantages of preorder and postorder traversals?
Parsing prefix and postfix notation?

Adding a sorted array to a bst causes an undesirable skewed tree. Searching/adding/removing values in a skewed tree can result in a change of O(LogN) to O(N).




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users