Given a pre-order sequence from a binary tree traversal, how many unique trees can be constructed? Give the recurrence relation.

Eg. given the pre-order traversal sequence 1, 2 you can create 2 unique trees:

 1      1
/        \

2 3

This leads to the obvious base cases:

T(0) = 1 T(1) = 1 T(2) = 2

what is T(N), where N is the number of elements in the sequence?

asked 05 Aug, 18:59

bryant's gravatar image

bryant
111
accept rate: 0%


T(n) = Sum( T(i) * T(n-1-i), i from 0 to n - 1)

link

answered 06 Aug, 08:32

cydu's gravatar image

cydu
113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • Indent code by 4 spaces.
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×27
×4
×3
×1

Asked: 05 Aug, 18:59

Seen: 421 times

Last updated: 06 Aug, 08:32