How do I approach the problem: Minimum amount of edges to remove to create k connected components? The graph might already be a forest, though not necessarily one with k connected components, and may have cycles. It is unweighted and undirected.
If the original graph is a tree, then the removal of each edge will increase the number of connected components by 1. After removing k-1 edges, the graph will become a forest with k connected components.
If the graph already has at least k components, then the answer is 0.
If the graph is a tree, then the answer is k-1.
If the graph is the complete graph with n nodes, then the answer is n-1 + n-2 + ... + n-k+1 = (n(n-1) - (n-k)(n-k+1))/2.
Without assumption, the answer can be any number between 0 and (n(n-1) - (n-k)(n-k+1))/2.
How many distinct graph can I have with n nodes (No label on Nodes, nor weight on Edges)? Is there a formula?
For example for a graph with 3 nodes I can just have a linear shape and a Triangular.
While we do have formulas for the number of non-isomorphic graphs, it appears that these formulas are quite hard to evaluate. The OEIS lists the numbers of distinct graphs for many numbers of nodes and includes references to papers that have worked out the details.
The number of distinct graphs grows extremely quickly as a function of the number of nodes. Asymptotically, the number of n-node non-isomorphic graphs is approximately 2n(n - 1) / 2 / n!. That intuitively makes sense; the numerator here counts the number of graphs on n labeled nodes, and the denominator counts the number of ways you can rearrange the labels on those nodes. Check the OEIS for links to proofs of this result.
Suppose each student has x enemies. We need to form groups in a class of 100 students such that no enemies are in the same group. Find the minimum number of groups needed in the worst case for x=1,2,3. How to proceed with this question ?
Consider a graph with vertices representing students and edges representing whether the two students are enemies.
A graph where each vertex has k adjacent vertices is called a k-regular graph.
The necessary and sufficient conditions for a k-regular graph of order n to exist are that k < n and that n*k is even.
Dividing the vertices of a graph into groups such that no two vertices in a group are adjacent is called vertex coloring, and the smallest number of such groups is called the chromatic number of the graph.
So, your problem can be stated as follows: Given two integers n and k < n, find the maximum chromatic number of a k-regular graph with n vertices.
To solve this, the Brooks' theorem can be used:
In a connected graph in which every vertex has at most Δ neighbors,
the vertices can be colored with only Δ colors, except for two cases,
complete graphs and cycle graphs of odd length, which require Δ + 1
colors.
I have a random graph G(n, p) with n = 5000 vertices and an edge probability of p = 0.004.
I wonder what would be the expected number of edges in the graph but I have not much knowledge in probability-theory.
Can anyone help me?
Thank you so much!
EDIT:
If pE is the number of possible edges in the Graph, wouldn't I have to calculate 0.004 * pE to get the expected number of edges in the graph?
First, ask yourself the maximum number of possible edges in the graph. This is when every vertex is connected to every single other vertex (nC2 = n * (n-1)/2), assuming this is an undirected graph without self-loops).
If each possible edge has a likelihood of 0.004, and the # of possible edges is n(n-1)/2, then the expected number of edges will be 0.004*(n(n-1)/2).
The number of expected vertices depend on the number of nodes and the edge probability as in E = p(n(n-1)/2).
The total number of possible edges in your graph is n(n-1) if any i is allowed to be linked to any j as both i->j and j->i. I am your friend, you are mine. If the graph is undirected (and an edge only means that we are friends) the total number of edges drop by half: n(n-1)/2 since i->j and j->i are the same.
The multiplication with p gives the expected number of edges, since every possible edge has become real or not depending on the probability. p=1 gives n(n-1)/2 edges since every possible edge actually happened. For graphs with p<1, the actual edge count might (obviously) differ from time to time if you were to actually generate a random graph using the p and n of your choice. Expected edge count will however be the most common observed edge count if you were to generate an infinite number of random graphs. NetLogo is a very pedagogical tool if you want to generate random graphs and get a feel for how network measurements arise from random graphs of different structures.
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