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
  • Where is the recursion in your analysis? To analyse a recursive algorithm you generally have to solve a recursion. – adrianN Oct 17 '17 at 07:59
  • We generally don't do "check my answer" style questions. Also, since you don't include the relevant pseudocode, nor any reasoning for your guesses, nothing can be said. I'll point you towards our reference question so you can start on a more structured attempt. – Raphael Oct 17 '17 at 09:29

0 Answers0