Let me write my first thread here about #binaryTrees and how #algorithms can differ from case to case.

So I wrote, in #python, 2 different implementations for an Integer Binary Tree:
- Recursive
- Iterative

You can check here the code: https://gist.github.com/ttiagojm/526b3f3634dbc751f693c81ae1e20996

And as you can see there is no gain, sometimes even recursion is faster than iterative.

Then I was intrigued by this result and I tried to run an identical test on a project.
1/2

A simple Integer Binary Tree implementation using both Iterative and Recursive implementation

A simple Integer Binary Tree implementation using both Iterative and Recursive implementation - bin_tree.py

Gist

Well, that project implements a binary tree to represent a Convolutional Neural Network.
It creates a random network, symbolically, and evaluates transforming it in a real #Keras model.

Testing on this gave a different result as you can see in the image above. Iterative mode is better and you don't get recursion errors because of recursion limits.

Recursion is more elegant and I like to think recursively, but normally iterative wins :)

2/2

I forgot to tell you about a weird behavior on #python.
When I tested with depth = 1 000 000 my recursive function is much much better than iterative!

I don't know if that's because the stack can't handle it or if Python is smart enough to save values from the current recursion call to use in the next recursion calls.

I know that having a list (in iterative mode) with so many nodes can make Python slower ... But it's weird.

That's my first thread here after #twitterMigration

@tiago_j_m Try it on Pypy, chances are it'll fly