MATLAB Answers

Create random graph with limited degree

11 views (last 30 days)
Sara on 12 Jul 2020
Commented: Sara on 13 Jul 2020
I want to create random and an undirected graph where the maximum degree of each node in the graph = 4, we can have in the graph nodes with the degree 2,3 or even 4 but none of them has a degree greater than 4, in other words, the degree of each node is between 1 and 4.
anyone can help?

Accepted Answer

Bruno Luong
Bruno Luong on 13 Jul 2020
n = 10; % number of nodes
maxDeg = 4;

More Answers (1)

Christine Tobler
Christine Tobler on 13 Jul 2020
You could start by just making an undirected graph, and then go through each node and compute its degree. If the degree is larger than 4, remove some of the edges connecting to that node at random.
Do you need it to be "uniformly" random, and if yes in which way?
  1 Comment
Sara on 13 Jul 2020
I will try that thank you verry much

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!