The maximum integer with the same lines, in red ebony

I have a tree with a set of numbers, where each number has two lines: a and b. Thus, the structure is as follows:

and number b

for each node.

I want to get the maximum number in the tree, where a = b in O (log n) is the worst execution time.

My approach: I tried red ebony. This has O (log n) if the number is in the right subtree. But O (n) if the number is in the left subtree.

Cant uses a regular BST since for the worst case it has O (n) as the runtime.

+4
source share
2 answers

; a == b a!= b. , , , O, 2 * O (log n) → O (log n).

+1

, .

.

// O (log n) .

" " Cormen . ( CLR-). .

. 14.1, ,

f - , - T n , f node x , x, left(x) right(x), f(left(x)) f(right(x)). f T O(log n) .

left (x) - x ..

g(node) node.number, node.a == node.b -infinity .

f(x) max f(left(x)), f(right(x)), g(x).

+2

All Articles