How can I combine two binary trees

I have two binary trees and I want to combine them. My first question is whether we can combine two binary trees, and if so, how efficiently can I perform merge operations and what are the different ways to perform merge operations ...

+7
source share
5 answers

Without considering efficiency, this answer can work The algorithm for combining two binary trees? . If sorted or balanced, discussion of effectiveness in How is the merger of two BSTs effective? and Merge / merge / merge two AVL trees

+2
source

1) Smooth both trees in sorted lists.
2) Drain the lists from what you got in 1)
3) Build a tree from what you got in 2)

+22
source
+5
source

Create a new node and point one tail at the head of one of the trees and point the other tail at the head of another tree. You may need to clarify your question to be more specific. What relationship are you trying to keep?

0
source

The tree is also a graph, therefore, we derive boundary vertex pairs (u, v) for each tree, and then combine these sets of edges and display the resulting graph.

The question arises of how to compare the vertices in one tree with the vertices in another (for example, we have a pair of edges (5,9) in tree 1 and a pair of edges (5,6) in tree 2, do these 5s correspond to the same top?).

Numbering vertices (it is possible that assigns numbers to each vertex in an incomplete binary tree, as if it were a complete binary tree, therefore, in other words, assigns vertices in any partial binary tree slots of a hypothetical full binary tree of which this tree is a subtree) that somehow provides the desired equivalence is what works.

0
source

All Articles