9.13 Reconstruct binary tree from preorder traversal with markers - improved space complexity

#1

The solution given in the book is recursive so it uses space O(h), where h is the height of the tree. However this can be improved to O(1), when the nodes have a parent pointer. I offer such an implemention here.

0 Likes

#2

hi @lgtout,

I am not sure this is Java or not, and I cannot understand this very well. Do you have a Java implementation?

0 Likes

#3

@tsunghsienlee
It runs in the JVM :slight_smile: . But no, it’s not Java . It’s Kotlin. Its more like Groovy (or Swift) than Java in syntax. I don’t have a Java language version.

0 Likes

#4

It would be great if you can write this in languages I can understand otherwise I have no idea to verify the idea.

0 Likes

#5

Valid point. Kotlin is primarily very popular among Android developers. So most people are unfamiliar with it.

0 Likes