Find most even trisection of a tree graph in O(n log n) time












3














I have been working on this for a few days, brushing up on graph theory and disjoint sets, but I have not yet found an algorithm that is guaranteed to produce the optimal result and runs in better than $O(n^2)$ time.



The problem is to divide a tree graph, which is a connected undirected graph with no cycles, into 3 equal parts. More formally, given a tree graph $G$ with $n$ vertices, find the most even partition of $G$ into $3$ components $A, B, C$ with $a, b, c$ vertices, respectively. For this problem, "most even" is defined as having the largest value of $abc$ possible for the given graph $G$.



What I am most interested in learning is if there are properties of tree graphs I can leverage into proving that a trisection is the best (most even) possible without (in pathological cases) having to try all possible trisections. For example, if the most even bisection is so lopsided that the smaller "half" has fewer than $n/3$ vertices, I'm almost sure that means the most even trisection will be achieved by most evenly bisecting one of the 2 halves. But I have not been able to prove it yet.



I'm going to call vertices "nodes" from here on because it is a shorter word.



It is easy to cut the graph optimally in half in $O(n)$ time. Every edge has $x$ nodes on one side and $(n-x)$ on the other. Because there is only one path from any node to any other, you can compute these values for every edge in $O(n)$ time, and while you are calculating that, you can just keep track of which edge has the closest to $n over 2$ nodes on one side of it. Because you have checked every edge, you know this is the best you can do, even if $x ll frac n2$. It might not be the only edge that produces those size partitions, but that is not a concern.



So far, however, I have not found a way to prove that a given pair of edges are the best choice to cut to partition non-trivial $G$ unless either (a) the result is perfect, or (b) I compare it to essentially every other combination of 2 edges. I do not really have to compare every combination all the time, often I can cut the search space down, but I have not figured out how to prove that I have found the best possible partition in less that $O(n^2)$ time.



Everything I have come up with so far fails for various kinds of edge cases. The simplest case is a star tree, $n$ nodes all connected to one central node of degree $n$. If all I am doing is naïvely comparing edges and cuts, I have to try all possible combinations.



I can rank the edges, like I did with bisecting the graph, except this time rank them on how close the are to having $n over 3$ nodes on one side, but what if I have a tree like this:



One-sided tree



$H$ is connected to 5 leaves and there are a total of 12 nodes in $G$. The edge closest to having $frac n3 = 4$ nodes on one side is the edge between $4$ and $5$, $(4,5)$, which splits $G$ into sets of 4 and 8 nodes. If I cut that edge, the next best edges to cut (if I am only looking at edges of $G$, and going by the ranking in the previous paragraph) are $(3,4)$ or $(5,6)$, but would result in partitions of ${8,1,3}$ and ${7,1,4}$ respectively. It will be a long time before I find the optimal solution of ${6,3,3}$.



Looking at this, I considered finding the best $frac 23$ cut and then cutting the larger set in half. Except for this graph, the best $frac 23$ cut is the same as the best $frac 13$ cut, so we would cut edges $(4,5)$ and $(H,6)$ giving us a ${6,2,4}$ partition.



Since bisecting the graph is easy, I looked at recursively bisecting the graph. I could build up a balanced binary tree of subgraphs, but I don't know what that would get me for a star graph or various kinds of lopsided graphs I can come up with. It might work to find an approximate answer, but I want to be sure I have the exact best answer.



The real graphs I am dealing with can be huge, up to $1,000,000$ vertices, so the $O(n^2)$ solution is not practical. The only real constraint I can rely on is that the diameter of the graph will not get out of control huge like that.



I am looking for either help finding the best edges to cut or help verifying that the partition I have found is the best possible for the given graph (or, of course, both.) Thanks.










share|cite|improve this question
























  • Not relevant to the question as asked, but: often in situations like this there can be algorithms that find an approximately correct solution that are faster than anything guaranteed to find the correct solution. Are you interested in such solutions or do you really need optimality?
    – Daniel McLaury
    Dec 26 at 3:26










  • @DanielMcLaury I already know how to make a good guess, a.k.a. find an approximately correct solution, so for the purposes of this question I'm only interested in something that guarantees optimality.
    – Old Pro
    2 days ago










  • It looks that it is not very easy to find a required algorithm. So if you will not obtain an answer here I recommend you to ask this question at CS Theory.SE.
    – Alex Ravsky
    2 days ago










  • I am confused. About looking for a bisection: Are you looking for the minimum number of edges to cut to bisect the tree into two forests $F_1$ and $F_2$ such that $F_1$ and $F_2$ have the same number of vertices (within 1). OR are you looking for the one edge to cut to get as close to a bisection as possible, cutting only one edge. Your title and intro says you are looking for the former but the rest of your text says you are looking for the latter.
    – Mike
    2 days ago












  • @Mike For a tree, any edge you cut will bisect the tree into a forest of 2 trees, and any 2 edges cut will trisect the tree. I changed the title for you anyway.
    – Old Pro
    2 days ago


















3














I have been working on this for a few days, brushing up on graph theory and disjoint sets, but I have not yet found an algorithm that is guaranteed to produce the optimal result and runs in better than $O(n^2)$ time.



The problem is to divide a tree graph, which is a connected undirected graph with no cycles, into 3 equal parts. More formally, given a tree graph $G$ with $n$ vertices, find the most even partition of $G$ into $3$ components $A, B, C$ with $a, b, c$ vertices, respectively. For this problem, "most even" is defined as having the largest value of $abc$ possible for the given graph $G$.



What I am most interested in learning is if there are properties of tree graphs I can leverage into proving that a trisection is the best (most even) possible without (in pathological cases) having to try all possible trisections. For example, if the most even bisection is so lopsided that the smaller "half" has fewer than $n/3$ vertices, I'm almost sure that means the most even trisection will be achieved by most evenly bisecting one of the 2 halves. But I have not been able to prove it yet.



I'm going to call vertices "nodes" from here on because it is a shorter word.



It is easy to cut the graph optimally in half in $O(n)$ time. Every edge has $x$ nodes on one side and $(n-x)$ on the other. Because there is only one path from any node to any other, you can compute these values for every edge in $O(n)$ time, and while you are calculating that, you can just keep track of which edge has the closest to $n over 2$ nodes on one side of it. Because you have checked every edge, you know this is the best you can do, even if $x ll frac n2$. It might not be the only edge that produces those size partitions, but that is not a concern.



So far, however, I have not found a way to prove that a given pair of edges are the best choice to cut to partition non-trivial $G$ unless either (a) the result is perfect, or (b) I compare it to essentially every other combination of 2 edges. I do not really have to compare every combination all the time, often I can cut the search space down, but I have not figured out how to prove that I have found the best possible partition in less that $O(n^2)$ time.



Everything I have come up with so far fails for various kinds of edge cases. The simplest case is a star tree, $n$ nodes all connected to one central node of degree $n$. If all I am doing is naïvely comparing edges and cuts, I have to try all possible combinations.



I can rank the edges, like I did with bisecting the graph, except this time rank them on how close the are to having $n over 3$ nodes on one side, but what if I have a tree like this:



One-sided tree



$H$ is connected to 5 leaves and there are a total of 12 nodes in $G$. The edge closest to having $frac n3 = 4$ nodes on one side is the edge between $4$ and $5$, $(4,5)$, which splits $G$ into sets of 4 and 8 nodes. If I cut that edge, the next best edges to cut (if I am only looking at edges of $G$, and going by the ranking in the previous paragraph) are $(3,4)$ or $(5,6)$, but would result in partitions of ${8,1,3}$ and ${7,1,4}$ respectively. It will be a long time before I find the optimal solution of ${6,3,3}$.



Looking at this, I considered finding the best $frac 23$ cut and then cutting the larger set in half. Except for this graph, the best $frac 23$ cut is the same as the best $frac 13$ cut, so we would cut edges $(4,5)$ and $(H,6)$ giving us a ${6,2,4}$ partition.



Since bisecting the graph is easy, I looked at recursively bisecting the graph. I could build up a balanced binary tree of subgraphs, but I don't know what that would get me for a star graph or various kinds of lopsided graphs I can come up with. It might work to find an approximate answer, but I want to be sure I have the exact best answer.



The real graphs I am dealing with can be huge, up to $1,000,000$ vertices, so the $O(n^2)$ solution is not practical. The only real constraint I can rely on is that the diameter of the graph will not get out of control huge like that.



I am looking for either help finding the best edges to cut or help verifying that the partition I have found is the best possible for the given graph (or, of course, both.) Thanks.










share|cite|improve this question
























  • Not relevant to the question as asked, but: often in situations like this there can be algorithms that find an approximately correct solution that are faster than anything guaranteed to find the correct solution. Are you interested in such solutions or do you really need optimality?
    – Daniel McLaury
    Dec 26 at 3:26










  • @DanielMcLaury I already know how to make a good guess, a.k.a. find an approximately correct solution, so for the purposes of this question I'm only interested in something that guarantees optimality.
    – Old Pro
    2 days ago










  • It looks that it is not very easy to find a required algorithm. So if you will not obtain an answer here I recommend you to ask this question at CS Theory.SE.
    – Alex Ravsky
    2 days ago










  • I am confused. About looking for a bisection: Are you looking for the minimum number of edges to cut to bisect the tree into two forests $F_1$ and $F_2$ such that $F_1$ and $F_2$ have the same number of vertices (within 1). OR are you looking for the one edge to cut to get as close to a bisection as possible, cutting only one edge. Your title and intro says you are looking for the former but the rest of your text says you are looking for the latter.
    – Mike
    2 days ago












  • @Mike For a tree, any edge you cut will bisect the tree into a forest of 2 trees, and any 2 edges cut will trisect the tree. I changed the title for you anyway.
    – Old Pro
    2 days ago
















3












3








3







I have been working on this for a few days, brushing up on graph theory and disjoint sets, but I have not yet found an algorithm that is guaranteed to produce the optimal result and runs in better than $O(n^2)$ time.



The problem is to divide a tree graph, which is a connected undirected graph with no cycles, into 3 equal parts. More formally, given a tree graph $G$ with $n$ vertices, find the most even partition of $G$ into $3$ components $A, B, C$ with $a, b, c$ vertices, respectively. For this problem, "most even" is defined as having the largest value of $abc$ possible for the given graph $G$.



What I am most interested in learning is if there are properties of tree graphs I can leverage into proving that a trisection is the best (most even) possible without (in pathological cases) having to try all possible trisections. For example, if the most even bisection is so lopsided that the smaller "half" has fewer than $n/3$ vertices, I'm almost sure that means the most even trisection will be achieved by most evenly bisecting one of the 2 halves. But I have not been able to prove it yet.



I'm going to call vertices "nodes" from here on because it is a shorter word.



It is easy to cut the graph optimally in half in $O(n)$ time. Every edge has $x$ nodes on one side and $(n-x)$ on the other. Because there is only one path from any node to any other, you can compute these values for every edge in $O(n)$ time, and while you are calculating that, you can just keep track of which edge has the closest to $n over 2$ nodes on one side of it. Because you have checked every edge, you know this is the best you can do, even if $x ll frac n2$. It might not be the only edge that produces those size partitions, but that is not a concern.



So far, however, I have not found a way to prove that a given pair of edges are the best choice to cut to partition non-trivial $G$ unless either (a) the result is perfect, or (b) I compare it to essentially every other combination of 2 edges. I do not really have to compare every combination all the time, often I can cut the search space down, but I have not figured out how to prove that I have found the best possible partition in less that $O(n^2)$ time.



Everything I have come up with so far fails for various kinds of edge cases. The simplest case is a star tree, $n$ nodes all connected to one central node of degree $n$. If all I am doing is naïvely comparing edges and cuts, I have to try all possible combinations.



I can rank the edges, like I did with bisecting the graph, except this time rank them on how close the are to having $n over 3$ nodes on one side, but what if I have a tree like this:



One-sided tree



$H$ is connected to 5 leaves and there are a total of 12 nodes in $G$. The edge closest to having $frac n3 = 4$ nodes on one side is the edge between $4$ and $5$, $(4,5)$, which splits $G$ into sets of 4 and 8 nodes. If I cut that edge, the next best edges to cut (if I am only looking at edges of $G$, and going by the ranking in the previous paragraph) are $(3,4)$ or $(5,6)$, but would result in partitions of ${8,1,3}$ and ${7,1,4}$ respectively. It will be a long time before I find the optimal solution of ${6,3,3}$.



Looking at this, I considered finding the best $frac 23$ cut and then cutting the larger set in half. Except for this graph, the best $frac 23$ cut is the same as the best $frac 13$ cut, so we would cut edges $(4,5)$ and $(H,6)$ giving us a ${6,2,4}$ partition.



Since bisecting the graph is easy, I looked at recursively bisecting the graph. I could build up a balanced binary tree of subgraphs, but I don't know what that would get me for a star graph or various kinds of lopsided graphs I can come up with. It might work to find an approximate answer, but I want to be sure I have the exact best answer.



The real graphs I am dealing with can be huge, up to $1,000,000$ vertices, so the $O(n^2)$ solution is not practical. The only real constraint I can rely on is that the diameter of the graph will not get out of control huge like that.



I am looking for either help finding the best edges to cut or help verifying that the partition I have found is the best possible for the given graph (or, of course, both.) Thanks.










share|cite|improve this question















I have been working on this for a few days, brushing up on graph theory and disjoint sets, but I have not yet found an algorithm that is guaranteed to produce the optimal result and runs in better than $O(n^2)$ time.



The problem is to divide a tree graph, which is a connected undirected graph with no cycles, into 3 equal parts. More formally, given a tree graph $G$ with $n$ vertices, find the most even partition of $G$ into $3$ components $A, B, C$ with $a, b, c$ vertices, respectively. For this problem, "most even" is defined as having the largest value of $abc$ possible for the given graph $G$.



What I am most interested in learning is if there are properties of tree graphs I can leverage into proving that a trisection is the best (most even) possible without (in pathological cases) having to try all possible trisections. For example, if the most even bisection is so lopsided that the smaller "half" has fewer than $n/3$ vertices, I'm almost sure that means the most even trisection will be achieved by most evenly bisecting one of the 2 halves. But I have not been able to prove it yet.



I'm going to call vertices "nodes" from here on because it is a shorter word.



It is easy to cut the graph optimally in half in $O(n)$ time. Every edge has $x$ nodes on one side and $(n-x)$ on the other. Because there is only one path from any node to any other, you can compute these values for every edge in $O(n)$ time, and while you are calculating that, you can just keep track of which edge has the closest to $n over 2$ nodes on one side of it. Because you have checked every edge, you know this is the best you can do, even if $x ll frac n2$. It might not be the only edge that produces those size partitions, but that is not a concern.



So far, however, I have not found a way to prove that a given pair of edges are the best choice to cut to partition non-trivial $G$ unless either (a) the result is perfect, or (b) I compare it to essentially every other combination of 2 edges. I do not really have to compare every combination all the time, often I can cut the search space down, but I have not figured out how to prove that I have found the best possible partition in less that $O(n^2)$ time.



Everything I have come up with so far fails for various kinds of edge cases. The simplest case is a star tree, $n$ nodes all connected to one central node of degree $n$. If all I am doing is naïvely comparing edges and cuts, I have to try all possible combinations.



I can rank the edges, like I did with bisecting the graph, except this time rank them on how close the are to having $n over 3$ nodes on one side, but what if I have a tree like this:



One-sided tree



$H$ is connected to 5 leaves and there are a total of 12 nodes in $G$. The edge closest to having $frac n3 = 4$ nodes on one side is the edge between $4$ and $5$, $(4,5)$, which splits $G$ into sets of 4 and 8 nodes. If I cut that edge, the next best edges to cut (if I am only looking at edges of $G$, and going by the ranking in the previous paragraph) are $(3,4)$ or $(5,6)$, but would result in partitions of ${8,1,3}$ and ${7,1,4}$ respectively. It will be a long time before I find the optimal solution of ${6,3,3}$.



Looking at this, I considered finding the best $frac 23$ cut and then cutting the larger set in half. Except for this graph, the best $frac 23$ cut is the same as the best $frac 13$ cut, so we would cut edges $(4,5)$ and $(H,6)$ giving us a ${6,2,4}$ partition.



Since bisecting the graph is easy, I looked at recursively bisecting the graph. I could build up a balanced binary tree of subgraphs, but I don't know what that would get me for a star graph or various kinds of lopsided graphs I can come up with. It might work to find an approximate answer, but I want to be sure I have the exact best answer.



The real graphs I am dealing with can be huge, up to $1,000,000$ vertices, so the $O(n^2)$ solution is not practical. The only real constraint I can rely on is that the diameter of the graph will not get out of control huge like that.



I am looking for either help finding the best edges to cut or help verifying that the partition I have found is the best possible for the given graph (or, of course, both.) Thanks.







graph-theory optimization algorithms trees set-partition






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited 23 hours ago

























asked Dec 26 at 1:46









Old Pro

280211




280211












  • Not relevant to the question as asked, but: often in situations like this there can be algorithms that find an approximately correct solution that are faster than anything guaranteed to find the correct solution. Are you interested in such solutions or do you really need optimality?
    – Daniel McLaury
    Dec 26 at 3:26










  • @DanielMcLaury I already know how to make a good guess, a.k.a. find an approximately correct solution, so for the purposes of this question I'm only interested in something that guarantees optimality.
    – Old Pro
    2 days ago










  • It looks that it is not very easy to find a required algorithm. So if you will not obtain an answer here I recommend you to ask this question at CS Theory.SE.
    – Alex Ravsky
    2 days ago










  • I am confused. About looking for a bisection: Are you looking for the minimum number of edges to cut to bisect the tree into two forests $F_1$ and $F_2$ such that $F_1$ and $F_2$ have the same number of vertices (within 1). OR are you looking for the one edge to cut to get as close to a bisection as possible, cutting only one edge. Your title and intro says you are looking for the former but the rest of your text says you are looking for the latter.
    – Mike
    2 days ago












  • @Mike For a tree, any edge you cut will bisect the tree into a forest of 2 trees, and any 2 edges cut will trisect the tree. I changed the title for you anyway.
    – Old Pro
    2 days ago




















  • Not relevant to the question as asked, but: often in situations like this there can be algorithms that find an approximately correct solution that are faster than anything guaranteed to find the correct solution. Are you interested in such solutions or do you really need optimality?
    – Daniel McLaury
    Dec 26 at 3:26










  • @DanielMcLaury I already know how to make a good guess, a.k.a. find an approximately correct solution, so for the purposes of this question I'm only interested in something that guarantees optimality.
    – Old Pro
    2 days ago










  • It looks that it is not very easy to find a required algorithm. So if you will not obtain an answer here I recommend you to ask this question at CS Theory.SE.
    – Alex Ravsky
    2 days ago










  • I am confused. About looking for a bisection: Are you looking for the minimum number of edges to cut to bisect the tree into two forests $F_1$ and $F_2$ such that $F_1$ and $F_2$ have the same number of vertices (within 1). OR are you looking for the one edge to cut to get as close to a bisection as possible, cutting only one edge. Your title and intro says you are looking for the former but the rest of your text says you are looking for the latter.
    – Mike
    2 days ago












  • @Mike For a tree, any edge you cut will bisect the tree into a forest of 2 trees, and any 2 edges cut will trisect the tree. I changed the title for you anyway.
    – Old Pro
    2 days ago


















Not relevant to the question as asked, but: often in situations like this there can be algorithms that find an approximately correct solution that are faster than anything guaranteed to find the correct solution. Are you interested in such solutions or do you really need optimality?
– Daniel McLaury
Dec 26 at 3:26




Not relevant to the question as asked, but: often in situations like this there can be algorithms that find an approximately correct solution that are faster than anything guaranteed to find the correct solution. Are you interested in such solutions or do you really need optimality?
– Daniel McLaury
Dec 26 at 3:26












@DanielMcLaury I already know how to make a good guess, a.k.a. find an approximately correct solution, so for the purposes of this question I'm only interested in something that guarantees optimality.
– Old Pro
2 days ago




@DanielMcLaury I already know how to make a good guess, a.k.a. find an approximately correct solution, so for the purposes of this question I'm only interested in something that guarantees optimality.
– Old Pro
2 days ago












It looks that it is not very easy to find a required algorithm. So if you will not obtain an answer here I recommend you to ask this question at CS Theory.SE.
– Alex Ravsky
2 days ago




It looks that it is not very easy to find a required algorithm. So if you will not obtain an answer here I recommend you to ask this question at CS Theory.SE.
– Alex Ravsky
2 days ago












I am confused. About looking for a bisection: Are you looking for the minimum number of edges to cut to bisect the tree into two forests $F_1$ and $F_2$ such that $F_1$ and $F_2$ have the same number of vertices (within 1). OR are you looking for the one edge to cut to get as close to a bisection as possible, cutting only one edge. Your title and intro says you are looking for the former but the rest of your text says you are looking for the latter.
– Mike
2 days ago






I am confused. About looking for a bisection: Are you looking for the minimum number of edges to cut to bisect the tree into two forests $F_1$ and $F_2$ such that $F_1$ and $F_2$ have the same number of vertices (within 1). OR are you looking for the one edge to cut to get as close to a bisection as possible, cutting only one edge. Your title and intro says you are looking for the former but the rest of your text says you are looking for the latter.
– Mike
2 days ago














@Mike For a tree, any edge you cut will bisect the tree into a forest of 2 trees, and any 2 edges cut will trisect the tree. I changed the title for you anyway.
– Old Pro
2 days ago






@Mike For a tree, any edge you cut will bisect the tree into a forest of 2 trees, and any 2 edges cut will trisect the tree. I changed the title for you anyway.
– Old Pro
2 days ago












1 Answer
1






active

oldest

votes


















0














I believe you can use Heavy Light Decomposition to get an $mathcal{O}(nlog^2n)$ time algorithm. This is quite complicated, so I will not bother with too many details. The idea is as follows.



Fix some root and determine the HLD. Then for every node we consider the subtree rooted at that node. We will call such subtrees rooted subtrees. We can easily do a linear time DFS to determine for every rooted subtree how many nodes it contains. Less obvious is that we can then do an $mathcal{O}(nlog^2n)$ time DFS on all heavy chains to determine for each rooted subtree the optimal $2$-cut of that subgraph. With all this information processed, we can find the optimal $3$-cut of the original graph in $mathcal{O}(nlog^2n)$ time.



The DFS on the heavy chains works as follows. For each chain, we work from bottom to top. We can keep track of all the sizes of rooted subtrees below the current node in a BST. So for each node $N$ in the heavy chain, from bottom to top, we add all sizes of rooted subtrees of its descendants not already in the BST (these can easily be found in linear time with a DFS), and then do a query to find the size closest to $s/2$ where $s$ is the size of the rooted subtree of $N$. Since each path from a root to a node intersects $mathcal{O}(log n)$ heavy chains, every node is only considered $mathcal{O}(log n)$ times. There are $n$ such nodes and BST operations cost $mathcal{O}(log n)$ time, so this step takes $mathcal{O}(nlog^2n)$ time in total.



Finally, finding the optimal $3$-cut of the original graph in linear time is still quite tedious. Any $3$-cut is itself a tree graph, when we connect two components if they are connected in the original graph. Notice there is only one possible tree graph with $3$ nodes. The root of our original graph will be in one component. We can consider two cases. The root component is connected to both other components, or only one.



If the root component is connected to only one other component, we can simply consider every possible rooted subtree and their optimal $2$-cut. Then you will find the optimal $3$-cut where the root component is connected to only one other component. This takes linear time.



If the root component is connected to both other components, things get a lot more complicated, and we will need to use our HLD again. We need a global BST for this step. It initially contains all sizes of rooted subtrees. For each heavy chain, we work from bottom to top. We want to consider for every node in the chain the optimal $3$-cut where one of the components is its rooted subtree. This means the other component that does not contain the root must be a disjoint rooted subtree. So we want to keep track of all such rooted subtrees in our BST.



If we traverse the heavy chains in a DFS, we can ensure that every rooted subtree containing the current heavy chain is already removed from the BST. Then, working from bottom to top, we can ensure that every rooted subtree below the current node is also removed from the BST. We can then do a $mathcal{O}(log n)$ BST query to find the optimal $3$-cut per node. Finally, we add all the rooted subtrees back to the BST. By similar analysis to before, this step will take $mathcal{O}(nlog^2n)$ time in total.






share|cite|improve this answer





















  • Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
    – Old Pro
    3 mins ago











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3052573%2ffind-most-even-trisection-of-a-tree-graph-in-on-log-n-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I believe you can use Heavy Light Decomposition to get an $mathcal{O}(nlog^2n)$ time algorithm. This is quite complicated, so I will not bother with too many details. The idea is as follows.



Fix some root and determine the HLD. Then for every node we consider the subtree rooted at that node. We will call such subtrees rooted subtrees. We can easily do a linear time DFS to determine for every rooted subtree how many nodes it contains. Less obvious is that we can then do an $mathcal{O}(nlog^2n)$ time DFS on all heavy chains to determine for each rooted subtree the optimal $2$-cut of that subgraph. With all this information processed, we can find the optimal $3$-cut of the original graph in $mathcal{O}(nlog^2n)$ time.



The DFS on the heavy chains works as follows. For each chain, we work from bottom to top. We can keep track of all the sizes of rooted subtrees below the current node in a BST. So for each node $N$ in the heavy chain, from bottom to top, we add all sizes of rooted subtrees of its descendants not already in the BST (these can easily be found in linear time with a DFS), and then do a query to find the size closest to $s/2$ where $s$ is the size of the rooted subtree of $N$. Since each path from a root to a node intersects $mathcal{O}(log n)$ heavy chains, every node is only considered $mathcal{O}(log n)$ times. There are $n$ such nodes and BST operations cost $mathcal{O}(log n)$ time, so this step takes $mathcal{O}(nlog^2n)$ time in total.



Finally, finding the optimal $3$-cut of the original graph in linear time is still quite tedious. Any $3$-cut is itself a tree graph, when we connect two components if they are connected in the original graph. Notice there is only one possible tree graph with $3$ nodes. The root of our original graph will be in one component. We can consider two cases. The root component is connected to both other components, or only one.



If the root component is connected to only one other component, we can simply consider every possible rooted subtree and their optimal $2$-cut. Then you will find the optimal $3$-cut where the root component is connected to only one other component. This takes linear time.



If the root component is connected to both other components, things get a lot more complicated, and we will need to use our HLD again. We need a global BST for this step. It initially contains all sizes of rooted subtrees. For each heavy chain, we work from bottom to top. We want to consider for every node in the chain the optimal $3$-cut where one of the components is its rooted subtree. This means the other component that does not contain the root must be a disjoint rooted subtree. So we want to keep track of all such rooted subtrees in our BST.



If we traverse the heavy chains in a DFS, we can ensure that every rooted subtree containing the current heavy chain is already removed from the BST. Then, working from bottom to top, we can ensure that every rooted subtree below the current node is also removed from the BST. We can then do a $mathcal{O}(log n)$ BST query to find the optimal $3$-cut per node. Finally, we add all the rooted subtrees back to the BST. By similar analysis to before, this step will take $mathcal{O}(nlog^2n)$ time in total.






share|cite|improve this answer





















  • Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
    – Old Pro
    3 mins ago
















0














I believe you can use Heavy Light Decomposition to get an $mathcal{O}(nlog^2n)$ time algorithm. This is quite complicated, so I will not bother with too many details. The idea is as follows.



Fix some root and determine the HLD. Then for every node we consider the subtree rooted at that node. We will call such subtrees rooted subtrees. We can easily do a linear time DFS to determine for every rooted subtree how many nodes it contains. Less obvious is that we can then do an $mathcal{O}(nlog^2n)$ time DFS on all heavy chains to determine for each rooted subtree the optimal $2$-cut of that subgraph. With all this information processed, we can find the optimal $3$-cut of the original graph in $mathcal{O}(nlog^2n)$ time.



The DFS on the heavy chains works as follows. For each chain, we work from bottom to top. We can keep track of all the sizes of rooted subtrees below the current node in a BST. So for each node $N$ in the heavy chain, from bottom to top, we add all sizes of rooted subtrees of its descendants not already in the BST (these can easily be found in linear time with a DFS), and then do a query to find the size closest to $s/2$ where $s$ is the size of the rooted subtree of $N$. Since each path from a root to a node intersects $mathcal{O}(log n)$ heavy chains, every node is only considered $mathcal{O}(log n)$ times. There are $n$ such nodes and BST operations cost $mathcal{O}(log n)$ time, so this step takes $mathcal{O}(nlog^2n)$ time in total.



Finally, finding the optimal $3$-cut of the original graph in linear time is still quite tedious. Any $3$-cut is itself a tree graph, when we connect two components if they are connected in the original graph. Notice there is only one possible tree graph with $3$ nodes. The root of our original graph will be in one component. We can consider two cases. The root component is connected to both other components, or only one.



If the root component is connected to only one other component, we can simply consider every possible rooted subtree and their optimal $2$-cut. Then you will find the optimal $3$-cut where the root component is connected to only one other component. This takes linear time.



If the root component is connected to both other components, things get a lot more complicated, and we will need to use our HLD again. We need a global BST for this step. It initially contains all sizes of rooted subtrees. For each heavy chain, we work from bottom to top. We want to consider for every node in the chain the optimal $3$-cut where one of the components is its rooted subtree. This means the other component that does not contain the root must be a disjoint rooted subtree. So we want to keep track of all such rooted subtrees in our BST.



If we traverse the heavy chains in a DFS, we can ensure that every rooted subtree containing the current heavy chain is already removed from the BST. Then, working from bottom to top, we can ensure that every rooted subtree below the current node is also removed from the BST. We can then do a $mathcal{O}(log n)$ BST query to find the optimal $3$-cut per node. Finally, we add all the rooted subtrees back to the BST. By similar analysis to before, this step will take $mathcal{O}(nlog^2n)$ time in total.






share|cite|improve this answer





















  • Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
    – Old Pro
    3 mins ago














0












0








0






I believe you can use Heavy Light Decomposition to get an $mathcal{O}(nlog^2n)$ time algorithm. This is quite complicated, so I will not bother with too many details. The idea is as follows.



Fix some root and determine the HLD. Then for every node we consider the subtree rooted at that node. We will call such subtrees rooted subtrees. We can easily do a linear time DFS to determine for every rooted subtree how many nodes it contains. Less obvious is that we can then do an $mathcal{O}(nlog^2n)$ time DFS on all heavy chains to determine for each rooted subtree the optimal $2$-cut of that subgraph. With all this information processed, we can find the optimal $3$-cut of the original graph in $mathcal{O}(nlog^2n)$ time.



The DFS on the heavy chains works as follows. For each chain, we work from bottom to top. We can keep track of all the sizes of rooted subtrees below the current node in a BST. So for each node $N$ in the heavy chain, from bottom to top, we add all sizes of rooted subtrees of its descendants not already in the BST (these can easily be found in linear time with a DFS), and then do a query to find the size closest to $s/2$ where $s$ is the size of the rooted subtree of $N$. Since each path from a root to a node intersects $mathcal{O}(log n)$ heavy chains, every node is only considered $mathcal{O}(log n)$ times. There are $n$ such nodes and BST operations cost $mathcal{O}(log n)$ time, so this step takes $mathcal{O}(nlog^2n)$ time in total.



Finally, finding the optimal $3$-cut of the original graph in linear time is still quite tedious. Any $3$-cut is itself a tree graph, when we connect two components if they are connected in the original graph. Notice there is only one possible tree graph with $3$ nodes. The root of our original graph will be in one component. We can consider two cases. The root component is connected to both other components, or only one.



If the root component is connected to only one other component, we can simply consider every possible rooted subtree and their optimal $2$-cut. Then you will find the optimal $3$-cut where the root component is connected to only one other component. This takes linear time.



If the root component is connected to both other components, things get a lot more complicated, and we will need to use our HLD again. We need a global BST for this step. It initially contains all sizes of rooted subtrees. For each heavy chain, we work from bottom to top. We want to consider for every node in the chain the optimal $3$-cut where one of the components is its rooted subtree. This means the other component that does not contain the root must be a disjoint rooted subtree. So we want to keep track of all such rooted subtrees in our BST.



If we traverse the heavy chains in a DFS, we can ensure that every rooted subtree containing the current heavy chain is already removed from the BST. Then, working from bottom to top, we can ensure that every rooted subtree below the current node is also removed from the BST. We can then do a $mathcal{O}(log n)$ BST query to find the optimal $3$-cut per node. Finally, we add all the rooted subtrees back to the BST. By similar analysis to before, this step will take $mathcal{O}(nlog^2n)$ time in total.






share|cite|improve this answer












I believe you can use Heavy Light Decomposition to get an $mathcal{O}(nlog^2n)$ time algorithm. This is quite complicated, so I will not bother with too many details. The idea is as follows.



Fix some root and determine the HLD. Then for every node we consider the subtree rooted at that node. We will call such subtrees rooted subtrees. We can easily do a linear time DFS to determine for every rooted subtree how many nodes it contains. Less obvious is that we can then do an $mathcal{O}(nlog^2n)$ time DFS on all heavy chains to determine for each rooted subtree the optimal $2$-cut of that subgraph. With all this information processed, we can find the optimal $3$-cut of the original graph in $mathcal{O}(nlog^2n)$ time.



The DFS on the heavy chains works as follows. For each chain, we work from bottom to top. We can keep track of all the sizes of rooted subtrees below the current node in a BST. So for each node $N$ in the heavy chain, from bottom to top, we add all sizes of rooted subtrees of its descendants not already in the BST (these can easily be found in linear time with a DFS), and then do a query to find the size closest to $s/2$ where $s$ is the size of the rooted subtree of $N$. Since each path from a root to a node intersects $mathcal{O}(log n)$ heavy chains, every node is only considered $mathcal{O}(log n)$ times. There are $n$ such nodes and BST operations cost $mathcal{O}(log n)$ time, so this step takes $mathcal{O}(nlog^2n)$ time in total.



Finally, finding the optimal $3$-cut of the original graph in linear time is still quite tedious. Any $3$-cut is itself a tree graph, when we connect two components if they are connected in the original graph. Notice there is only one possible tree graph with $3$ nodes. The root of our original graph will be in one component. We can consider two cases. The root component is connected to both other components, or only one.



If the root component is connected to only one other component, we can simply consider every possible rooted subtree and their optimal $2$-cut. Then you will find the optimal $3$-cut where the root component is connected to only one other component. This takes linear time.



If the root component is connected to both other components, things get a lot more complicated, and we will need to use our HLD again. We need a global BST for this step. It initially contains all sizes of rooted subtrees. For each heavy chain, we work from bottom to top. We want to consider for every node in the chain the optimal $3$-cut where one of the components is its rooted subtree. This means the other component that does not contain the root must be a disjoint rooted subtree. So we want to keep track of all such rooted subtrees in our BST.



If we traverse the heavy chains in a DFS, we can ensure that every rooted subtree containing the current heavy chain is already removed from the BST. Then, working from bottom to top, we can ensure that every rooted subtree below the current node is also removed from the BST. We can then do a $mathcal{O}(log n)$ BST query to find the optimal $3$-cut per node. Finally, we add all the rooted subtrees back to the BST. By similar analysis to before, this step will take $mathcal{O}(nlog^2n)$ time in total.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered yesterday









SmileyCraft

2,584414




2,584414












  • Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
    – Old Pro
    3 mins ago


















  • Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
    – Old Pro
    3 mins ago
















Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
– Old Pro
3 mins ago




Thank you for thinking hard about this. I'm not completely following your answer yet, but so far it seems to me this still might be problematic in pathological cases. For example, there is no guarantee about how many heavy chains you end up with in HLD: in a star, all but 1 vertex has degree 1, so every edge is a heavy chain (or light edge, depending on your flavor of HLD). And if finding the optimal 2-cut is O(n), doing it n times makes it O(n^2) as you know. Plus I'm still not sure how you keep track in O(1) time and O(n) space of which vertices are in which component after cutting 2 edges.
– Old Pro
3 mins ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3052573%2ffind-most-even-trisection-of-a-tree-graph-in-on-log-n-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Human spaceflight

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

張江高科駅