In this article, we are going to see Star Graph using Networkx Python. A Star graph is a special type of graph in which n-1 vertices have degree 1 and a single vertex have degree n – 1. This looks like that n – 1 vertex is connected to a single central vertex. A star graph with total n – vertex is termed as Sn.
Properties of Star Graph:
- It has n+1 vertices.
- It has n edges.
- It does not have any cycle.
- The diameter of a star graph Sn is a minimum of (2, n).
- A Star graph is a tree.
- It has no unconnected component.
- The chromatic number of the star graph is a minimum of (2, n + 1).
Example of S10 :
Example of S6 :
- We will import the required networkx module
- After that, we will initialize a number of nodes to 6.
- We will create graph object G using star_graph() function.
- We will realize the graph using nx.draw() function.
- We will make the color of nodes green and increasing size by passing extra arguments to nx.draw().
As we passed 6 as an argument to the star_graph() function hence we got a star graph with 6 edges as output. We changed the color and size of nodes by passing extra arguments node_size and node_color to the nx.draw() function.
As we passed 10 as an argument to the star_graph() function hence we got a star graph with 10 edges as output. We changed the color and size of nodes by passing extra arguments node_size and node_color to the nx.draw() function.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course