1

I studied this algorithm. Link.
Is is about finding all possible binary trees with given inorder traversal.

I want to analyze this code with Big-O notation.
I think it is O(N^3). Below is my thought.

1) choose root node. let's say in[i]. (0 <= i < N). => O(N)
2) construct left subtree. in[0] ~ in[i-1]. => O(N)
3) construct right subtree. in[i+1] ~ in[N-1]. => O(N)

In order to count all cases, I considered product rule. So I concluded time complexity of this algorithm is O(N^3).

Is it correct?

newbie16
  • 135
  • 1
  • 3

0 Answers0