473,513 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merging two AVL treees

I had a test today and there was a question regarding how to merge two
AVL trees to form another AVL tree without using any AVL tree
operations. Some had done it by using an array, sorted the elements
and then formed the tree. Is there any sort of 'appropriate' algorithm
for doing this? (This seems sort of brute force).

Apr 13 '07 #1
4 6798
ga***************@gmail.com wrote:
I had a test today and there was a question regarding how to merge two
AVL trees to form another AVL tree without using any AVL tree
operations.
Cannot be done, for exceedingly obvious reasons.
Some had done it by using an array, sorted the elements
and then formed the tree.
And how, then, did he "form the tree" without using any AVL tree
operations? It seems to me that building an AVL tree _is_ an AVL tree
operation.
Is there any sort of 'appropriate' algorithm for doing this?
Yes. Use the tools. Don't work around them.

Richard
Apr 13 '07 #2
On Apr 13, 1:23 am, gagan.singh.ar...@gmail.com wrote:
I had a test today and there was a question regarding how to merge two
AVL trees to form another AVL tree without using any AVL tree
operations. Some had done it by using an array, sorted the elements
and then formed the tree. Is there any sort of 'appropriate' algorithm
for doing this? (This seems sort of brute force).
You want news:comp.programming, where you will (no doubt) run into Ben
Pfaff (who is quite the AVL tree expert).

I guess that merging two properly formed AVL trees can be a lot more
efficient than simply cramming the smaller tree into the larger, one
object at a time, if there is a merge() function.

But your question is not a C question but an algorithm question.
While news:comp.programming is not exactly an algorithms group, it's
the closest thing that I know of.

Apr 13 '07 #3
On Apr 13, 3:01 pm, "user923005" <dcor...@connx.comwrote:
On Apr 13, 1:23 am, gagan.singh.ar...@gmail.com wrote:
I had a test today and there was a question regarding how to merge two
AVL trees to form another AVL tree without using any AVL tree
operations. Some had done it by using an array, sorted the elements
and then formed the tree. Is there any sort of 'appropriate' algorithm
for doing this? (This seems sort of brute force).

You want news:comp.programming, where you will (no doubt) run into Ben
Pfaff (who is quite the AVL tree expert).

I guess that merging two properly formed AVL trees can be a lot more
efficient than simply cramming the smaller tree into the larger, one
object at a time, if there is a merge() function.

But your question is not a C question but an algorithm question.
While news:comp.programming is not exactly an algorithms group, it's
the closest thing that I know of.
This article

http://groups.google.com/group/comp....46b2801c4f84e?

discusses how to build a balanced BST in O(n) time with O(log n) space
if you have input that's already sorted. So to merge _any_ set of
binary BSTs, just traverse them with in-order iterators, always
picking the least iterator value, and inserting this value into a new
balanced BST. It's easy to set the AVL flags on the fly as the new BST
is created or afterward in a separate O(n) pass.
Apr 14 '07 #4
"user923005" <dc*****@connx.comwrites:
On Apr 13, 1:23 am, gagan.singh.ar...@gmail.com wrote:
>I had a test today and there was a question regarding how to merge two
AVL trees to form another AVL tree without using any AVL tree
operations. Some had done it by using an array, sorted the elements
and then formed the tree. Is there any sort of 'appropriate' algorithm
for doing this? (This seems sort of brute force).

You want news:comp.programming, where you will (no doubt) run into Ben
Pfaff (who is quite the AVL tree expert).
I think that this question is answered in Knuth. It's actually
a coding exercise that I've never properly explored. Perhaps I
will do so for the next version of libavl, should I ever acquire
a round tuit.
--
"To get the best out of this book, I strongly recommend that you read it."
--Richard Heathfield
Apr 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2527
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I...
2
1527
by: Klatuu | last post by:
Whew, I've struggled my way through figuring out how to use XML to transport data..now I can imagine what having a baby is like :) But, I'm stuck now. I generate the XML (single table, no...
3
1872
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best,...
2
5550
by: Emmett Power | last post by:
Hi, I have an Access table with a number of records which refer to the same person but with data in different fields. So for example the table would look like this: Name..............Field...
1
4915
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
0
1135
by: Naresh Narwani | last post by:
Problem Summary: Merging two different web applications into one create a problem for User Controls. Reason for merging two different Web Application: To share non serializable object...
2
1177
by: Ponnurangam | last post by:
Hi, I have created two styles from cssclass and merged first one with the second one. I then used the style for an Item. The styles are not merging. Here is the code that I used Dim...
2
2414
by: Dave Taylor | last post by:
Is there a decent explanation of how menu merging with MDI forms work in VB.NET? I've read through the online help and it still seems that whenever I change menus around or whatever, it breaks...
7
1756
by: Jon Vaughan | last post by:
I have 2 datasets , one returned as a dataset from a webservice and one created client side form the same stored procedure that is returned from the webservice. I then try and merge the data, but...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.