Dado el número de vértices y el número de aristas de un gráfico no dirigido. La tarea es determinar el rango del circuito.
Rango de circuito: El rango de circuito de un grafo no dirigido se define como el número mínimo de aristas que se deben quitar del grafo para romper todos sus ciclos, convirtiéndolo en un árbol o bosque.
Ejemplos :
Input : Edges = 7 , Vertices = 5 Output : Circuit rank = 3 Input : Edges = 7 , Vertices = 6 Output : Circuit rank = 2
Fórmula :
Circuit rank = Edges - (Vertices - 1)
Mire el gráfico de muestra a continuación,
Número total de aristas = 7 y vértices = 5.
De acuerdo con la fórmula anterior,
Circuit Rank = Edges - (Vertices - 1) = 7 - (5 - 1) = 3
Por lo tanto, Rango de circuito del gráfico anterior = 3.
En la imagen a continuación se puede ver que al eliminar 3 bordes (ad, ae, cd) del gráfico anterior, se pueden eliminar todos sus ciclos.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find Circuit Rank of an Undirected Graph #include <bits/stdc++.h> using namespace std; // Function that calculates the // Circuit rank of the Graph. int Rank(int Edges, int Vertices) { int result = 0; // calculates Circuit Rank result = Edges - Vertices + 1; return result; } // Driver Code int main() { int Edges = 7, Vertices = 5; cout << "Circuit Rank = " << Rank(Edges, Vertices); return 0; }
Java
//Java Program to find Circuit Rank of an Undirected Graph public class GFG { //Function that calculates the //Circuit rank of the Graph. static int Rank(int Edges, int Vertices) { int result = 0; // calculates Circuit Rank result = Edges - Vertices + 1; return result; } //Driver Code public static void main(String[] args) { int Edges = 7, Vertices = 5; System.out.println("Circuit Rank = " + Rank(Edges, Vertices)); } }
Python 3
# Python 3 program to find Circuit Rank of # an Undirected Graph # Function that calculates the # Circuit rank of the Graph. def Rank(Edges, Vertices) : # calculates Circuit Rank result = Edges - Vertices + 1 return result # Driver code if __name__ == "__main__" : Edges, Vertices = 7, 5 print("Circuit Rank =",Rank(Edges, Vertices)) # This code is contributed by ANKITRAI1
C#
// C# Program to find Circuit // Rank of an Undirected Graph using System; class GFG { // Function that calculates the // Circuit rank of the Graph. static int Rank(int Edges, int Vertices) { int result = 0; // calculates Circuit Rank result = Edges - Vertices + 1; return result; } // Driver Code public static void Main() { int Edges = 7, Vertices = 5; Console.WriteLine("Circuit Rank = " + Rank(Edges, Vertices)); } } // This code is contributed // by inder_verma
PHP
<?php // PHP Program to find Circuit Rank of an Undirected Graph // Function that calculates the // Circuit rank of the Graph. function Rank($Edges, $Vertices) { $result = 0; // calculates Circuit Rank $result = $Edges - $Vertices + 1; return $result; } // Driver Code $Edges = 7; $Vertices = 5; echo ("Circuit Rank = "); echo (Rank($Edges, $Vertices)); // This code is contributed // by Shivi_Aggarwal ?>
Javascript
<script> // Javascript Program to find Circuit // Rank of an Undirected Graph // Function that calculates the // Circuit rank of the Graph. function Rank(Edges, Vertices) { var result = 0; // calculates Circuit Rank result = Edges - Vertices + 1; return result; } // Driver Code var Edges = 7, Vertices = 5; document.write( "Circuit Rank = " + Rank(Edges, Vertices)); </script>
Circuit Rank = 3
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