In a directed acyclic graph with n vertices, what is the maximum possible number of directed edges in it?
Assume N vertices/nodes, and let's explore building up a DAG with maximum edges. Consider any given node, say N1. The maximum # of nodes it can point to, or edges, at this early stage is N-1. Let's choose a second node N2: it can point to all nodes except itself and N1 - that's N-2 additional edges. Continue for remaining nodes, each can point to one less edge than the node before. The last node can point to 0 other nodes.
Sum of all edges: (N-1) + (N-2) + .. + 1 + 0 == (N-1)(N)/2
Related
I have a directed unweighted graph with N nodes and E edges. Nodes are of an average degree 2E/N.
In the first round, nodes each broadcast their information to all their neighbours. In subsequent rounds, nodes broadcast the information received from their neighbours during the previous round to all other neighbours, and so forth.
The graph is not guaranteed to be acyclic.
My question is: how many consecutive rounds of broadcast are required, on average, for 95% of node pairs to have reached one another? Is it possible to calculate an approximate figure based on the average degree of the graph?
By average, I assume you mean average over all possible (N,E) directed graphs with no multiple edges.
Theorem 1
If E <= (N-1)^2, there will be at least one graph where information won't propagate.
Proof
A directed graph with N nodes has up to N(N-1) edges. Consider a complete graph, select a node, and remove all its outgoing edges (Alternatively, we can remove all its incoming edges). Information from this node cannot propagate, and we are left with N(N-1)-(N-1) = (N-1)^2 edges.
Corollary 1
When E <= (N-1)^2, there is at least one graph where information cannot propagate, therefore the average number of rounds is infinite.
Theorem 2a
If E > (N-1)^2 the maximal number of rounds is 2.
Proof
A directed graph with N nodes and E > (N-1)^2 edges is a complete graph where up to (N-2) edges removed.
If we want to remove edges from a complete graph such the the number of rounds will be 3 (e.g. from node A to node B), we'll need to make sure there is no node B and edges A->B and B->C. This means that we need to remove at least one edge (either A->B or B->C) for each of the (N-2) possible 'B' nodes. We also need to remove the direct A->C edge. In total we need to remove (N-3) edges.
Theorem 2b
If E > (N-1)^2 the minimal number of rounds is 2.
Proof
Trivial. The graph is incomplete, therefore there is at least one path of length 2.
Corollary 2
if (N-1)^2 < E < N(N-1), the number of rounds is 2.
Theorem 3
If E = N(N-1), the number of rounds is 1
Proof
Trivial. Complete graph.
Now, you are asking about more than 95% of the node pairs.
Of course we can build some (N-1)^2 < E < N(N-1) graphs, where >= 95% of ordered-node-pairs can communicate in 1 round, but the other ordered-node-pairs communicate in 2 rounds.
This is trivial if you consider a complete directed graph of 6 nodes where only one edge is removed. (6*5-1) / (6*5) = 96.66% of the ordered-node-pairs can communicate in one round.
Why do you ask specifically about 95%? Is it important to derive calculations for exactly this number? Let us know. I don't think that you can derive a simple accurate generic formula, especially when N and E are small. Maybe we can formulate something asymptotically (for very large N).
I know that for an undirected graph with n vertices to be connected it must have n - 1 edges. However, my question is what is the minimum number of edges that it can have for it to always be connected. For example, does a graph with n vertices and n + 2 edges have to be always be connected? If not, what is the number of edges it must have for it to always be connected?
If you allow for repeated connections then there is no maximum number. (For example you have 3 vertices a,b,c and the edge (a,b) appears infinity many times but there is no edge that connects with c). So to make this interesting lets say you can't have repeated connections.
For your case of n+2 edges consider if you had a graph with 10 vertices and its edges form two disjoint copies of k5. k5 has 10 edges so we have a a graph with 10 vertices and 20 edges which works as a counter example to your claim. However if you notice in my example if we don't disconnect any edges you cannot add one without connecting the graph.
Another example we can consider (again with 10 vertices) is k9 and a single vertex. k9 has 36 edges (more than my previous example) and the single vertex makes the graph disjoint. In general your maximal example will be k(n-1) and a single vertex.
km has m(m-1)/2 edges so the maximum number of edges you can have and still have a disjoint graph is (n-1)(n-2)/2. Meaning the minimal number of edges to guarantee a n vertex graph (with no self loops or multiple connections) is (n-1)(n-2)/2 + 1.
the maximum number of edges that a n vertices graph can have to not be connected is n-2.
for a graph having 3 vertices you need atleast 2 edges to make it connected which is n-1 so one edge lesser than that will give you the maximum edges with which graph will be disconnected.
does a graph with n vertices and n + 2 edges have to be always be connected : depends whether self loops are allowed or not for example consider a case of 3 vertices and 5 edges so it will be connected by 2 edges and 3 self loops but fir the case of 4 vertices and 6 edges it's possible also and not possible too.
I couldn't answer the question myself because i don't see any similar behavior for all the examples i tried.
The question again:
Maximum number of edges in undirected graph with n vertices with k connected components?
Thanks.
This answer depends on whether your graphs are allowed to have self-loops or not. For simplicity, I'm going to assume they aren't.
If you have a connected component with x nodes in it, the maximum number of edges you can have in that connected component is x(x - 1) / 2. Therefore, if you have n total nodes and k different connected components, you can imagine distributing the nodes into the connected components in a way that maximizes the sum of x(x - 1) / 2 across the connected components.
Specifically, suppose your CC's have n1, ..., nk nodes each. You want to solve the following quadratic program:
Maximize: n1(n1 - 1) / 2 + ... + nk(nk - 1) / 2
Subject to: n1 + ... + nk = n
I'm going to claim that this is maximized when k - 1 of the connected components have 1 node and the last connected component has n - k + 1 nodes in it. Intuitively, this is true because any node you remove from the huge CC will cause a large drop in the number of possible edges that will not be offset by the meager increase in the number of possible edges in the other connected component the node was added to.
Under this setup, the maximum number of possible edges in the k - 1 singleton CC's will be 0 and the maximum number of possible edges in the other CC will be (n - k + 1)(n - k) / 2. Therefore, the total should be (n - k + 1)(n - k) / 2.
Hope this helps!
when graph do not contain self loops and is undirected then the maximum no. of edges are-
(n-k+1)(n-k)/2
It is because maximum number of edges with n vertices is n(n-1)/2. Now for example, if we are making an undirected graph with n=2 (4 vertices) and there are 2 connected components i.e, k=2, then first connected component contains either 3 vertices or 2 vertices, for simplicity we take 3 vertices (Because connected component containing 2 vertices each will not results in maximum number of edges). These 3 vertices must be connected so maximum number of edges between these 3 vertices are 3 i.e, (1->2->3->1) and the second connected component contains only 1 vertex which has no edge. So the maximum number of edges in this case are 3. This implies that replacing n with n-k+1 in the formula for maximum number of edges i.e, n(n-1)/2 will results in (n-k+1)(n-k)/2 which is maximum number of edges that a graph of n vertices with k connected component can have.see image for better understanding
hope it will be helpful!!
Okay, I know that a directed acyclic graph (DAG) has E=V-1 edges. E = number of edges. V = number of vertices.
So the question is, "In a directed graph G, the number of edges is always less than the number of vertices." True or false?
Thanks for the help.
Assume N vertices/nodes, and let's explore building up a DAG with maximum edges. Consider any given node, say N1. The maximum # of nodes it can point to, or edges, at this early stage is N-1. Let's choose a second node N2: it can point to all nodes except itself and N1 - that's N-2 additional edges. Continue for remaining nodes, each can point to one less edge than the node before. The last node can point to 0 other nodes.
Sum of all edges: (N-1) + (N-2) + .. + 1 + 0 == (N-1)(N)/2
Given an undirected graph in which each node has a Cartesian coordinate in space that has the general shape of a tree, is there an algorithm to convert the graph into a tree, and find the appropriate root node?
Note that our definition of a "tree" requires that branches do not diverge from parent nodes at acute angles.
See the example graphs below. How do we find the red node?
here is a suggestion on how to solve your problem.
prerequisites
notation:
g graph, g.v graph vertices
v,w,z: individual vertices
e: individual edge
n: number of vertices
any combination of an undirected tree g and a given node g.v uniquely determines a directed tree with root g.v (provable by induction)
idea
complement the edges of g by orientations in the directed tree implied by g and the yet-to-be-found root node by local computations at the nodes of g.
these orientations will represent child-parent-relationsships between nodes (v -> w: v child, w parent).
the completely marked tree will contain a sole node with outdegree 0, which is the desired root node. you might end up with 0 or more than one root node.
algorithm
assumes standard representation of the graph/tree structure (eg adjacency list)
all vertices in g.v are marked initially as not visited, not finished.
visit all vertices in arbitrary sequence. skip nodes marked as 'finished'.
let v be the currently visited vertex.
2.1 sweep through all edges linking v clockwise starting with a randomly chosen e_0 in the order of the edges' angle with e_0.
2.2. orient adjacent edges e_1=(v,w_1), e_2(v,w_2), that enclose an acute angle.
adjacent: wrt being ordered according to the angle they enclose with e_0.
[ note: the existence of such a pair is not guaranteed, see 2nd comment and last remark. if no angle is acute, proceed at 2. with next node. ]
2.2.1 the orientations of edges e_1, e_2 are known:
w_1 -> v -> w_2: impossible, as a grandparent-child-segment would enclose an acute angle
w_1 <- v <- w_2: impossible, same reason
w_1 <- v -> w_2: impossible, there are no nodes with outdegree >1 in a tree
w_1 -> v <- w_2:
only possible pair of orientations. e_1, e_2 might have been oriented before. if the previous orientation violates the current assignment, the problem instance has no solution.
2.2.2 this assignment implies a tree structure on the subgraphs induced by all vertices reachable from w_1 (w_2) on a path not comprising e_1 (e_2`). mark all vertices in both induced subtrees as finished
[ note: the subtree structure might violate the angle constraints. in this case the problem has no solution. ]
2.3 mark v visited. after completing steps 2.2 at vertex v, check the number nc of edges connecting that have not yet been assigned an orientation.
nc = 0: this is the root you've been searching for - but you must check whether the solution is compatible with your constraints.
nc = 1: let this edge be (v,z).
the orientation of this edge is v->z as you are in a tree. mark v as finished.
2.3.1 check z whether it is marked finished.
if it is not, check the number nc2 of unoriented edges connecting z.
nc2 = 1: repeat step 2.3 by taking z for v.
if you have not yet found a root node, your problem instance is ambiguous:
orient the remaining unoriented edges at will.
remarks
termination:
each node is visited at max 4 times:
once per step 2
at max twice per step 2.2.2
at max once per step 2.3
correctness:
all edges enclosing an acute angle are oriented per step 2.2.1
complexity (time):
visiting every node: O(n);
the clockwise sweep through all edges connecting a given vertex requires these edges to be sorted.
thus you need O( sum_i=1..m ( k_i * lg k_i ) ) at m <= n vertices under the constraint sum_i=1..m k_i = n.
in total this requires O ( n * lg n), as sum_i=1..m ( k_i * lg k_i ) <= n * lg n given sum_i=1..m k_i = n for any m <= n (provable by applying lagrange optimization).
[ note: if your trees have a degree bounded by a constant, you theoretically sort in constant time at each node affected; grand total in this case: O(n) ]
subtree marking:
each node in the graph is visited at max 2 times by this procedure if implemented as a dfs. thus a grand total of O(n) for the invocation of this subroutine.
in total: O(n * lg n)
complexity (space):
O(n) for sorting (with vertex-degree not constant-bound).
problem is probably ill-defined:
multiple solutions: e.g. steiner tree
no solution: e.g. graph shaped like a double-tipped arrow (<->)
A simple solution would be to define a 2d rectangle around the red node or the center of your node and compute each node with a moore curve. A moore curve is a space-filling curve, more over a special version of a hilbert curve where the start and end vertex is the same and the coordinate is in the middle of the 2d rectangle. In generell your problem looks like a discrete addressing space problem.