Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Consider a new B-tree operation COMBINE (T1,T2,k). This operation takes as input two B-trees T1 and T2 with the same minimum degree parameter t, plus a new key k that does not appear in either T1 or T2. We assume that all the keys in T1 are strictly smaller than k and all the keys in T2 are strictly larger than k. The COMBINE operation produces a new B-tree T , with the same minimum degree t, whose keys are those in T1, those in T2, plus k. In the process, it destroys the original trees T1 and T2. In this problem, you will design an algorithm to implement the COMBINE operation. Your algorithm should run in time O(|h1 − h2| + 1), where h1 and h2 are the heights of trees T1 and T2 respectively. In analyzing the costs, you should regard t as a constant. First consider the special case of the problem in which h1 is assumed to be equal to h2. Give an algorithm to combine the trees that runs in constant time.

What I have tried:

array a[0..n−1];
key k begin l ← 0;
r ← n−1
while l ≤ r
do m ← n
(l+r)/2
if
a[m]<k
then
l←m+1
else if
a[m]>k
then
r←m−1
else return
m
end if
end while
return
not found
Posted
Updated 13-Apr-18 4:56am
Comments
OriginalGriff 13-Apr-18 10:46am    
What error?
How did you test it?
What data did you test it with?
What happened when you tested it?

1 solution

Looks like you have an advanced homework to do, but really no clue.

Here you find some tutorial about binary tree in C++.

Before you can code your solution you must enhance your skills by Learn C++ or the language you are coding.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900