Dado el número de vértices en un gráfico de ciclo. La tarea es encontrar el Grado y el número de Bordes del gráfico de ciclo.
Grado: El grado de cualquier vértice se define como el número de aristas que inciden sobre él.
Gráfico de ciclo: en la teoría de gráficos, un gráfico que consta de un solo ciclo se denomina gráfico de ciclo o gráfico circular . El gráfico de ciclo con n vértices se llama Cn .
Propiedades del gráfico de ciclo: –
- Es un grafo conectado.
- Un gráfico de ciclo o gráfico circular es un gráfico que consta de un solo ciclo.
- En un gráfico de ciclo, el número de vértices es igual al número de aristas.
- Un Cycle Graph es coloreable de 2 aristas o de 2 vértices, si y solo si tiene un número par de vértices.
- Un Cycle Graph es coloreable de 3 bordes o coloreable de 3 bordes, si y solo si tiene un número impar de vértices.
- En un gráfico de ciclo, el grado de cada vértice en un gráfico es dos.
- El grado de un gráfico de ciclo es 2 veces el número de vértices. Como cada borde se cuenta dos veces.
Ejemplos:
Input: Number of vertices = 4 Output: Degree is 8 Edges are 4 Explanation: The total edges are 4 and the Degree of the Graph is 8 as 2 edge incident on each of the vertices i.e on a, b, c, and d.
Input: number of vertices = 5 Output: Degree is 10 Edges are 5
A continuación se muestra la implementación del problema anterior:
Programa 1: Para gráfico de ciclo de 4 vértices
C++
// C++ implementation of above program. #include <bits/stdc++.h> using namespace std; // function that calculates the // number of Edge in a cycle graph. int getnumberOfEdges(int numberOfVertices) { int numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree int getDegree(int numberOfVertices) { int degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code int main() { // Get the number of vertices int numberOfVertices = 4; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result cout << "For numberOfVertices = " << numberOfVertices << "\nDegree = " << getDegree(numberOfVertices) << "\nNumber of Edges = " << getnumberOfEdges(numberOfVertices); return 0; }
Java
// Java implementation of above program. import java.io.*; class GFG { // function that calculates the // number of Edge in a cycle graph. static int getnumberOfEdges(int numberOfVertices) { int numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree static int getDegree(int numberOfVertices) { int degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code public static void main(String[] args) { // Get the number of vertices int numberOfVertices = 4; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result System.out.print("For numberOfVertices = " + numberOfVertices + "\nDegree = " + getDegree(numberOfVertices) + "\nNumber of Edges = " + getnumberOfEdges(numberOfVertices)); } } // This code is contributed by anuj_67..
Python3
# Python3 implementation of above program. # function that calculates the # number of Edge in a cycle graph. def getnumberOfEdges(numberOfVertices) : # The numberOfEdges of the cycle graph # will be same as the numberOfVertices numberOfEdges = numberOfVertices # return the numberOfEdges return numberOfEdges # function that calculates the degree def getDegree(numberOfVertices) : # The degree of the cycle graph # will be twice the numberOfVertices degree = 2 * numberOfVertices # return the degree return degree # Driver code if __name__ == "__main__" : # Get the number of vertices numberOfVertices = 4 # Find the numberOfEdges and degree # from the numberOfVertices # and print the result print("For numberOfVertices =", numberOfVertices, "\nDegree =", getDegree(numberOfVertices), "\nNumber of Edges =", getnumberOfEdges(numberOfVertices)) # This code is contributed by ANKITRAI1
C#
// C# implementation of above program. using System; class GFG { // function that calculates the // number of Edge in a cycle graph. static int getnumberOfEdges(int numberOfVertices) { int numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree static int getDegree(int numberOfVertices) { int degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code public static void Main() { // Get the number of vertices int numberOfVertices = 4; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result Console.WriteLine("For numberOfVertices = " + numberOfVertices + "\nDegree = " + getDegree(numberOfVertices) + "\nNumber of Edges = " + getnumberOfEdges(numberOfVertices)); } } // This code is contributed by anuj_67..
PHP
<?php // PHP implementation of above program // function that calculates the // number of Edge in a cycle graph. function getnumberOfEdges($numberOfVertices) { $numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices $numberOfEdges = $numberOfVertices; // return the numberOfEdges return $numberOfEdges; } // function that calculates the degree function getDegree($numberOfVertices) { // The degree of the cycle graph // will be twice the numberOfVertices $degree = 2 * $numberOfVertices; // return the degree return $degree; } // Driver code // Get the number of vertices $numberOfVertices = 4; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result echo ("For numberOfVertices = "); echo ($numberOfVertices); echo ("\nDegree = "); echo getDegree($numberOfVertices); echo("\nNumber of Edges = "); echo getnumberOfEdges($numberOfVertices); // This code is contributed by Shivi_Aggarwal ?>
Javascript
<script> // Javascript implementation of above program. // function that calculates the // number of Edge in a cycle graph. function getnumberOfEdges(numberOfVertices) { var numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree function getDegree(numberOfVertices) { var degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code // Get the number of vertices var numberOfVertices = 4; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result document.write("For numberOfVertices = " + numberOfVertices + "<br>Degree = " + getDegree(numberOfVertices) + "<br>Number of Edges = " + getnumberOfEdges(numberOfVertices)); // This code is contributed by itsok </script>
For numberOfVertices = 4 Degree = 8 Number of Edges = 4
Programa 2: Para gráfico de ciclo de 6 vértices
C++
// C++ implementation of above program. #include <bits/stdc++.h> using namespace std; // function that calculates the // number of Edge in a cycle graph. int getnumberOfEdges(int numberOfVertices) { int numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree int getDegree(int numberOfVertices) { int degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code int main() { // Get the number of vertices int numberOfVertices = 6; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result cout << "For numberOfVertices = " << numberOfVertices << "\nDegree = " << getDegree(numberOfVertices) << "\nNumber of Edges = " << getnumberOfEdges(numberOfVertices); return 0; }
Java
// Java implementation of above program. class GfG { // function that calculates the // number of Edge in a cycle graph. static int getnumberOfEdges(int numberOfVertices) { int numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree static int getDegree(int numberOfVertices) { int degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code public static void main(String[] args) { // Get the number of vertices int numberOfVertices = 6; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result System.out.println("For numberOfVertices = " + numberOfVertices + "\nDegree = " + getDegree(numberOfVertices) + "\nNumber of Edges = " + getnumberOfEdges(numberOfVertices)); } } // This code contributed by Rajput-Ji
Python3
# Python 3 implementation of above program # function that calculates the # number of Edge in a cycle graph. def getnumberOfEdges(numberOfVertices): numberOfEdges = 0 # The numberOfEdges of the cycle graph # will be same as the numberOfVertices numberOfEdges = numberOfVertices # return the numberOfEdges return numberOfEdges # function that calculates the degree def getDegree(numberOfVertices): # The degree of the cycle graph # will be twice the numberOfVertices degree = 2 * numberOfVertices # return the degree return degree # Driver code if __name__ == "__main__": # Get the number of vertices numberOfVertices = 6 # Find the numberOfEdges and degree # from the numberOfVertices # and print the result print("For numberOfVertices = ", numberOfVertices, "\nDegree = ", getDegree(numberOfVertices), "\nNumber of Edges = ", getnumberOfEdges(numberOfVertices)) # This code is contributed by ChitraNayal
C#
// C# implementation of above program. class GfG { // function that calculates the // number of Edge in a cycle graph. static int getnumberOfEdges(int numberOfVertices) { int numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree static int getDegree(int numberOfVertices) { int degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code static void Main() { // Get the number of vertices int numberOfVertices = 6; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result System.Console.WriteLine("For numberOfVertices = " + numberOfVertices + "\nDegree = " + getDegree(numberOfVertices) + "\nNumber of Edges = " + getnumberOfEdges(numberOfVertices)); } } // This code contributed by mits
PHP
<?php // PHP implementation of above program. // function that calculates the // number of Edge in a cycle graph. function getnumberOfEdges($numberOfVertices) { $numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices $numberOfEdges = $numberOfVertices; // return the numberOfEdges return $numberOfEdges; } // function that calculates the degree function getDegree($numberOfVertices) { $degree = 0; // The degree of the cycle graph // will be twice the numberOfVertices $degree = 2 * $numberOfVertices; // return the degree return $degree; } // Driver code // Get the number of vertices $numberOfVertices = 6; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result echo "For numberOfVertices = " . $numberOfVertices . "\nDegree = " . getDegree($numberOfVertices) . "\nNumber of Edges = " . getnumberOfEdges($numberOfVertices); // This code is contributed by mits ?>
Javascript
<script> // Javascript implementation of above program // function that calculates the // number of Edge in a cycle graph. function getnumberOfEdges(numberOfVertices) { let numberOfEdges = 0; // The numberOfEdges of the cycle graph // will be same as the numberOfVertices numberOfEdges = numberOfVertices; // return the numberOfEdges return numberOfEdges; } // function that calculates the degree function getDegree(numberOfVertices) { let degree; // The degree of the cycle graph // will be twice the numberOfVertices degree = 2 * numberOfVertices; // return the degree return degree; } // Driver code // Get the number of vertices let numberOfVertices = 6; // Find the numberOfEdges and degree // from the numberOfVertices // and print the result document.write("For numberOfVertices = " + numberOfVertices + "<br>Degree = " + getDegree(numberOfVertices) + "<br>Number of Edges = " + getnumberOfEdges(numberOfVertices)); // This code is contributed by avanitrachhadiya2155 </script>
For numberOfVertices = 6 Degree = 12 Number of Edges = 6
Publicación traducida automáticamente
Artículo escrito por Naman_Garg y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA