Morris algorithms for bintree

They’re algorithms to explore a binary tree without recursion.

All these algorithms move down the tree like a fractal, right to left, from bigger to smaller.

In inorder, you print the root when you’re going back smaller to bigger (meaning you already explored stuff on the left).

In preorder, you print the root when you’re going bigger to smaller (before exploring stuff on the left).

In postorder, you print the diagonals in reverse order when going smaller to bigger.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store