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
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.
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
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
What is the maximum number of edges in a directed graph with n nodes? Is there any upper bound?
If you have N nodes, there are N - 1 directed edges than can lead from it (going to every other node). Therefore, the maximum number of edges is N * (N - 1).
Directed graph:
Question: What's the maximum number of edges in a directed graph with n vertices?
Assume there are no self-loops.
Assume there there is at most one edge from a given start vertex to a given end vertex.
Each edge is specified by its start vertex and end vertex. There are n
choices for the start vertex. Since there are no self-loops, there are
n-1 choices for the end vertex. Multiplying these together counts all
possible choices.
Answer: n(n−1)
Undirected graph
Question: What's the maximum number of edges in an undirected graph with n vertices?
Assume there are no self-loops.
Assume there there is at most one edge from a given start vertex to a given end vertex.
In an undirected graph, each edge is specified by its two endpoints
and order doesn't matter. The number of edges is therefore the number
of subsets of size 2 chosen from the set of vertices. Since the set of
vertices has size n, the number of such subsets is given by the
binomial coefficient C(n,2) (also known as "n choose 2"). Using the
formula for binomial coefficients, C(n,2) = n(n-1)/2.
Answer: (n*(n-1))/2
In an undirected graph (excluding multigraphs), the answer is n*(n-1)/2. In a directed graph an edge may occur in both directions between two nodes, then the answer is n*(n-1).
In addition to the intuitive explanation Chris Smith has provided, we can consider why this is the case from a different perspective: considering undirected graphs.
To see why in a DIRECTED graph the answer is n*(n-1), consider an undirected graph (which simply means that if there is a link between two nodes (A and B) then you can go in both ways: from A to B and from B to A). The maximum number of edges in an undirected graph is n(n-1)/2 and obviously in a directed graph there are twice as many.
Good, you might ask, but why are there a maximum of n(n-1)/2 edges in an undirected graph?
For that, Consider n points (nodes) and ask how many edges can one make from the first point. Obviously, n-1 edges. Now how many edges can one draw from the second point, given that you connected the first point? Since the first and the second point are already connected, there are n-2 edges that can be done. And so on. So the sum of all edges is:
Sum = (n-1)+(n-2)+(n-3)+...+3+2+1
Since there are (n-1) terms in the Sum, and the average of Sum in such a series is ((n-1)+0)/2 {(last + first)/2}, Sum = n(n-1)/2
If the graph is not a multi graph then it is clearly n * (n - 1), as each node can at most have edges to every other node. If this is a multigraph, then there is no max limit.
Putting it another way:
A complete graph is an undirected graph where each distinct pair of vertices has an unique edge connecting them. This is intuitive in the sense that, you are basically choosing 2 vertices from a collection of n vertices.
nC2 = n!/(n-2)!*2! = n(n-1)/2
This is the maximum number of edges an undirected graph can have. Now, for directed graph, each edge converts into two directed edges. So just multiply the previous result with two. That gives you the result: n(n-1)
In a directed graph having N vertices, each vertex can connect to N-1 other vertices in the graph(Assuming, no self loop). Hence, the total number of edges can be are N(N-1).
In the graph with self loop
max edges= n*n
such as we have 4 nodes(vertex)
4 nodes = 16 edges= 4*4
There can be as many as n(n-1)/2 edges in the graph if not multi-edge is allowed.
And this is achievable if we label the vertices 1,2,...,n and there's an edge from i to j iff i>j.
See here.
The correct answer is n*(n-1)/2. Each edge has been counted twice, hence the division by 2. A complete graph has the maximum number of edges, which is given by n choose 2 = n*(n-1)/2.
Can also be thought of as the number of ways of choosing pairs of nodes n choose 2 = n(n-1)/2. True if only any pair can have only one edge. Multiply by 2 otherwise
Undirected is N^2. Simple - every node has N options of edges (himself included), total of N nodes thus N*N