An algorithm with time complexity below O(N^2) can exist only if each solution for a tree with nodes N can be encoded in less than O(N^2) .
Suppose a complete binary tree with N leaves ( N=n log n ). The solution to the problem will contain a path for each set of 2 sheets. This means that the solution will have elements O(N^2) . Thus, for this case, we can code the solution as 2-element leaf sets.
Now consider an almost complete binary tree with m leaves, which was created by removing only arbitrary leaves from a complete binary tree with leaves N Comparing the solution to this tree with the solution to a complete binary tree, both will share empty pools. In fact, for each subset of the ways to solve a complete binary tree, there will be at least one binary tree with m leaves, as indicated above, which contains all the solutions of such a subset. (We intentionally ignore the fact that a tree with leaves m may have several more paths in the solution, where at least some of the ends of the path are not leaves of a complete binary tree.)
Only this part of the solution for a binary tree with m leaves will be encoded with a number with bits (n^2)/2 . The bit index in this number is an element in the upper right half of the matrix with columns and rows N
For n=4 it will be:
x012 xx34 xxx5
The bit with index i will be set if the undirected path row(i),column(i) contained in the solution.
As we have already established, a solution for a tree with leaves m can contain any subset of the solution for a complete binary tree with leaves n>=m , each binary number with bits (n^2)/2 will be a solution for a tree with leaves m .
Now encoding all possible numbers using (n^2)/2 bits with less than (n^2)/2 not possible. So, we have shown that solutions, at least, require a representation of the space O(N^2) . Using N=n log n from above, we obtain a space requirement of at least O(N^2) .
Therefore, there is a doens't algorithm with time complexity less than O(N^2)
Spacetracker
source share