The degree of a vertex is defined as the number of edges connected to it. The degree sequence of a graph is a list of vertex degrees sorted in non-increasing order. This information is crucial for many graph-theoretic algorithms, including those related to network connectivity and flow.
- Graph Class: Contains methods to add vertices and edges and to compute the degrees.
- add_vertex(vertex): Adds a new vertex to the graph if it does not already exist.
- add_edge(vertex1, vertex2): Creates an undirected edge by adding both vertices to each other's adjacency list.
- degree(vertex): Calculates the degree by returning the length of the adjacency list for the specified vertex.
- degree_sequence(): Compiles the degree of all vertices, sorts them in non-increasing order, and returns the degree sequence.
Output: show the degree sequence of the constructed graph based on the vertices and edges added.