T is a positive-number sorted array in ascending order and the numbers are unique, T is a subset of {1,2,3,...,511}.
k is a positve number and k <= |T|
Label the numbers from 1 to 511 in a perfect binary tree:
1 2 3 4
1
2 3
4 5 6 7
.............................
You can open the picture if you can not imagine what the tree looks like.
Now try to find the first occurrence of the following number set(S) in T:
1) T[0](the first number in T) must be in S
2) try to use the small numbers as much as possible
3) k = |S|
4) if (x,y) is in S, then x is not the ancestor of y and y is not the ancestor of x in the tree.
I develop an top-to-down recursive algorithm, but it is too slow when there are more than 200 elements.
I feel like I am not understanding the rules.
1 can't be in the table -- is ancestor of everything except itself.
rules say 1 must be in table.
unless T[0] means something else.
Then either those aren't values in the tree (and I have no idea what those numbers are if they are not values in the tree), or...it isn't a binary tree - not by the classic meaning of that term.
What is it?
If you say it is a binary tree, there are no binary tree algorithms that could search that tree if this lists the values of the leaves. The tree could be traversed, by the standard binary tree algorithms would not list the values in order.
Maybe it is being called a binary tree in the context of your work or study, but it isn't a standard definition. It may be a kind of directed graph or some other data structure.
This looks like the numbers of blocks in a pyramid...well, one side of it or just a triangle if this is 2d (and not necessarily square blocks or tiles), which is the layout of a geometric structure.
@Niccolo
Wu zhen hai's use of terminology is correct. What's depicted is a perfect (albeit truncated) binary tree. It's just not a binary search tree.
@Wu zhen hai
We don't know what algorithm you're using nor how you implemented it. Showing the code that's "too slow" would help us help you immensely.