Can anybody help me to write a program in 'c' to merge the content of two binary search trees into one.and what will be the time &stroage complexities of that solution.
you mean the entire code .... I may write if I find time but chances are very thin ...
The algo is really simple ....
I presume that you have inorder traversal function which returns you one node
Describe the rules of your two trees. Can both trees contain the same results? Can they contain some of the same results? Will one tree be a subset of the other?
Kent
0
Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.
Sorry, but this sounds like a homework assignment and the member are prohibited from doing homework for others. We can help you to write your own.
I assume that you already have the code to build the BST. If so, merging two trees is a piece of cake.
Using one tree as the 'base', scan the other tree node by node. Every time you encounter a node, simply add it to the base tree. The base tree will now include both trees. (You can delete the second tree if you wish.)
My question(s) above were to see if there were a shortcut based on the data values. It doesn't appear that there is. Consider these two trees:
200
/ \
/ \
100 300
150
/ \
/ \
50 250
Neither tree can be grafted onto the other in such a way that order integrity is maintained. Hence the need to traverse the nodes of one of the trees and add each node to the other tree.
Like an array.
suppose two sorted arrays are there(simulate it like we are traversing tree in inorder)
first element of array will be compared to other one.and resultant element will go to new array.
Accordingly point to next elemet in thearray , from which element has not been pcked.
Does this answer ir question.
Is it not possible , to insert element in its proper position at the time of insertion.
I mean whenever we go for insertion , we will insert the node at its position and apply re-arrangment if required.
right, but you have included the efforts required to rearrange tree as and when required.
It might be that for every node insertion , tree has to be revisit/reshuffled completly.
right, but you have not included the efforts required to rearrange tree as and when required.
It might be that for every node insertion , tree has to be revisit/reshuffled completly.
going by above algorith choose 10 as left child and 120 as right child
34 remaining elements [3 7] [22] [66 87] [139]
/ \
10 120
and so on ....
since your array is sorted, all elements to the left of ith element will be in the left subtree and all elements to the right of ith element will be in the right subtree ....
In light of this fact, you should be able to build the tree in O(n) without any reshuffling
This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net. To view more iPhone tutorials, visit www.sdkexpert.net.
This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…