codeparrot/xlcost-text-to-code huggingface dataset:
Eulerian Path in undirected graph | Efficient C # program to find out Eulerian path ; Function to find out the path It takes the adjacency matrix representation of the graph as input ; Find out number of edges each vertex has ; Find out how many vertex has odd number edges ; If number of vertex with odd number of edges is greater than two return " No ▁ Solution " . ; If there is a path find the path Initialize empty stack and path take the starting current as discussed ; Loop will run until there is element in the stack or current edge has some neighbour . ; If current node has not any neighbour add it to path and pop stack set new current to the popped element ; If the current vertex has at least one neighbour add the current vertex to stack , remove the edge between them and set the current to its neighbour . ; print the path ; Driver Code ; Test case 1 ; Test case 2 ; Test case 3
using System ; using System . Collections . Generic ; class GFG { static void findpath ( int [ , ] graph , int n ) { List < int > numofadj = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) numofadj . Add ( accumulate ( graph , i , 0 ) ) ; int startPoint = 0 , numofodd = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( numofadj [ i ] % 2 == 1 ) { numofodd ++ ; startPoint = i ; } } if ( numofodd > 2 ) { Console . WriteLine ( " No ▁ Solution " ) ; return ; } Stack < int > stack = new Stack < int > ( ) ; List < int > path = new List < int > ( ) ; int cur = startPoint ; while ( stack . Count != 0 || accumulate ( graph , cur , 0 ) != 0 ) { if ( accumulate ( graph , cur , 0 ) == 0 ) { path . Add ( cur ) ; cur = stack . Pop ( ) ; } else { for ( int i = 0 ; i < n ; i ++ ) { if ( graph [ cur , i ] == 1 ) { stack . Push ( cur ) ; graph [ cur , i ] = 0 ; graph [ i , cur ] = 0 ; cur = i ; break ; } } } } foreach ( int ele in path ) Console . Write ( ele + " ▁ - > ▁ " ) ; Console . WriteLine ( cur ) ; } static int accumulate ( int [ , ] matrix , int row , int sum ) { int [ ] arr = GetRow ( matrix , row ) ; foreach ( int i in arr ) sum += i ; return sum ; } public static int [ ] GetRow ( int [ , ] matrix , int row ) { var rowLength = matrix . GetLength ( 1 ) ; var rowVector = new int [ rowLength ] ; for ( var i = 0 ; i < rowLength ; i ++ ) rowVector [ i ] = matrix [ row , i ] ; return rowVector ; } public static void Main ( String [ ] args ) { int [ , ] graph1 = { { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 1 , 0 } , { 0 , 1 , 1 , 0 , 0 } , { 1 , 0 , 0 , 0 , 0 } } ; int n = graph1 . GetLength ( 0 ) ; findpath ( graph1 , n ) ; int [ , ] graph2 = { { 0 , 1 , 0 , 1 , 1 } , { 1 , 0 , 1 , 0 , 1 } , { 0 , 1 , 0 , 1 , 1 } , { 1 , 1 , 1 , 0 , 0 } , { 1 , 0 , 1 , 0 , 0 } } ; n = graph2 . GetLength ( 0 ) ; findpath ( graph2 , n ) ; int [ , ] graph3 = { { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 , 1 } , { 0 , 1 , 0 , 1 , 0 } , { 0 , 1 , 1 , 0 , 1 } , { 1 , 1 , 0 , 1 , 0 } } ; n = graph3 . GetLength ( 0 ) ; findpath ( graph3 , n ) ; } }
Array element with minimum sum of absolute differences | C # implementation of the approach ; Function to return the minimized sum ; Sort the array ; Median of the array ; Calculate the minimized sum ; Return the required sum ; Driver code
using System ; class GFG { static int minSum ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int x = arr [ ( int ) ( n / 2 ) ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += Math . Abs ( arr [ i ] - x ) ; return sum ; } static void Main ( ) { int [ ] arr = { 1 , 3 , 9 , 3 , 6 } ; int n = arr . Length ; Console . WriteLine ( minSum ( arr , n ) ) ; } }
Sort even and odd placed elements in increasing order | C # implementation of the approach ; function to print the odd and even indexed digits ; lists to store the odd and even positioned digits ; traverse through all the indexes in the integer ; if the digit is in odd_index position append it to odd_position list ; else append it to the even_position list ; print the elements in the list in sorted order ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void odd_even ( int [ ] arr , int n ) { List < int > odd_indexes = new List < int > ( ) ; List < int > even_indexes = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) odd_indexes . Add ( arr [ i ] ) ; else even_indexes . Add ( arr [ i ] ) ; } odd_indexes . Sort ( ) ; even_indexes . Sort ( ) ; for ( int i = 0 ; i < odd_indexes . Count ; i ++ ) Console . Write ( odd_indexes [ i ] + " ▁ " ) ; for ( int i = 0 ; i < even_indexes . Count ; i ++ ) Console . Write ( even_indexes [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 7 , 6 , 8 } ; int n = arr . Length ; odd_even ( arr , n ) ; } }
Number of pairs whose sum is a power of 2 | C # implementation of above approach ; Function to return the count of valid pairs ; Storing occurrences of each element ; Start taking largest element each time ; If element has already been paired ; Find the number which is greater than a [ i ] and power of two ; If there is a number which adds up with a [ i ] to form a power of two ; Edge case when a [ i ] and crr - a [ i ] is same and we have only one occurrence of a [ i ] then it cannot be paired ; Remove already paired elements ; Return the count ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int countPairs ( int [ ] a , int n ) { Dictionary < int , int > map = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! map . ContainsKey ( a [ i ] ) ) map . Add ( a [ i ] , 1 ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( map [ a [ i ] ] < 1 ) continue ; int cur = 1 ; while ( cur <= a [ i ] ) cur <<= 1 ; if ( map . ContainsKey ( cur - a [ i ] ) ) { if ( cur - a [ i ] == a [ i ] && map [ a [ i ] ] == 1 ) continue ; count ++ ; map [ cur - a [ i ] ] = map [ cur - a [ i ] ] - 1 ; map [ a [ i ] ] = map [ a [ i ] ] - 1 ; } } return count ; } public static void Main ( String [ ] args ) { int [ ] a = { 3 , 11 , 14 , 5 , 13 } ; int n = a . Length ; Console . WriteLine ( countPairs ( a , n ) ) ; } }
Maximizing the elements with a [ i + 1 ] > a [ i ] | C # implementation of the approach ; returns the number of positions where A ( i + 1 ) is greater than A ( i ) after rearrangement of the array ; Creating a HashMap containing char as a key and occurrences as a value ; Find the maximum frequency ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int countMaxPos ( int [ ] arr ) { int n = arr . Length ; Dictionary < int , int > map = new Dictionary < int , int > ( ) ; foreach ( int x in arr ) { if ( map . ContainsKey ( x ) ) map [ x ] = map [ x ] + 1 ; else map . Add ( x , 1 ) ; } int max_freq = 0 ; foreach ( KeyValuePair < int , int > entry in map ) max_freq = Math . Max ( max_freq , entry . Value ) ; return n - max_freq ; } public static void Main ( String [ ] args ) { int [ ] arr = { 20 , 30 , 10 , 50 , 40 } ; Console . WriteLine ( countMaxPos ( arr ) ) ; } }
Rearrange all elements of array which are multiples of x in increasing order | C # implementation of the approach ; Function to sort all the multiples of x from the array in ascending order ; Insert all multiples of 5 to a vector ; Sort the vector ; update the array elements ; Driver code ; Print the result
using System ; using System . Collections . Generic ; class GFG { static void sortMultiples ( int [ ] arr , int n , int x ) { List < int > v = new List < int > ( ) ; int i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] % x == 0 ) v . Add ( arr [ i ] ) ; v . Sort ( ) ; int j = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % x == 0 ) arr [ i ] = v [ j ++ ] ; } } public static void Main ( ) { int [ ] arr = { 125 , 3 , 15 , 6 , 100 , 5 } ; int x = 5 ; int n = arr . Length ; sortMultiples ( arr , n , x ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } }
Minimum increment in the sides required to get non | C # Program to find Minimum increment in the sides required to get non - negative area of a triangle ; push the three sides to a array ; sort the array ; check if sum is greater than third side ; Driver Code
using System ; class GFG { static int minimumIncrease ( int a , int b , int c ) { int [ ] arr = { a , b , c } ; Array . Sort ( arr ) ; if ( arr [ 0 ] + arr [ 1 ] >= arr [ 2 ] ) return 0 ; else return arr [ 2 ] - ( arr [ 0 ] + arr [ 1 ] ) ; } public static void Main ( ) { int a = 3 , b = 5 , c = 10 ; Console . Write ( minimumIncrease ( a , b , c ) ) ; } }
Minimum sum of differences with an element in an array | C # program to find minimum sum of absolute differences with an array element . ; function to find min sum after operation ; Sort the array ; Pick middle value ; Sum of absolute differences . ; Driver Code
using System ; class GFG { static int absSumDidd ( int [ ] a ) { Array . Sort ( a ) ; int midValue = a [ a . Length / 2 ] ; int sum = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { sum = sum + Math . Abs ( a [ i ] - midValue ) ; } return sum ; } public static void Main ( ) { int [ ] arr = { 5 , 11 , 14 , 10 , 17 , 15 } ; Console . Write ( absSumDidd ( arr ) ) ; }
Printing frequency of each character just after its consecutive occurrences | C # program to print run length encoding of a string ; Counting occurrences of s [ i ] ; Driver code
using System ; class GFG { static void printRLE ( String s ) { for ( int i = 0 ; i < s . Length - 1 ; i ++ ) { int count = 1 ; while ( s [ i ] == s [ i + 1 ] ) { i ++ ; count ++ ; if ( i + 1 == s . Length ) break ; } Console . Write ( s [ i ] + " " + count + " ▁ " ) ; } Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { printRLE ( " GeeeEEKKKss " ) ; printRLE ( " ccccOddEEE " ) ; } }
Word Ladder ( Length of shortest chain to reach a target word ) | C # program to find length of the shortest chain transformation from source to target ; Returns length of shortest chain to reach ' target ' from ' start ' using minimum number of adjacent moves . D is dictionary ; If the target String is not present in the dictionary ; To store the current chain length and the length of the words ; Push the starting word into the queue ; While the queue is non - empty ; Increment the chain length ; Current size of the queue ; Since the queue is being updated while it is being traversed so only the elements which were already present in the queue before the start of this loop will be traversed for now ; Remove the first word from the queue ; For every character of the word ; Retain the original character at the current position ; Replace the current character with every possible lowercase alphabet ; If the new word is equal to the target word ; Remove the word from the set if it is found in it ; And push the newly generated word which will be a part of the chain ; Restore the original character at the current position ; Driver code ; make dictionary
using System ; using System . Collections . Generic ; class GFG { static int shortestChainLen ( String start , String target , HashSet < String > D ) { if ( start == target ) return 0 ; if ( ! D . Contains ( target ) ) return 0 ; int level = 0 , wordlength = start . Length ; List < String > Q = new List < String > ( ) ; Q . Add ( start ) ; while ( Q . Count != 0 ) { ++ level ; int sizeofQ = Q . Count ; for ( int i = 0 ; i < sizeofQ ; ++ i ) { char [ ] word = Q [ 0 ] . ToCharArray ( ) ; Q . RemoveAt ( 0 ) ; for ( int pos = 0 ; pos < wordlength ; ++ pos ) { char orig_char = word [ pos ] ; for ( char c = ' a ' ; c <= ' z ' ; ++ c ) { word [ pos ] = c ; if ( String . Join ( " " , word ) . Equals ( target ) ) return level + 1 ; if ( ! D . Contains ( String . Join ( " " , word ) ) ) continue ; D . Remove ( String . Join ( " " , word ) ) ; Q . Add ( String . Join ( " " , word ) ) ; } word [ pos ] = orig_char ; } } } return 0 ; } public static void Main ( String [ ] args ) { HashSet < String > D = new HashSet < String > ( ) ; D . Add ( " poon " ) ; D . Add ( " plee " ) ; D . Add ( " same " ) ; D . Add ( " poie " ) ; D . Add ( " plie " ) ; D . Add ( " poin " ) ; D . Add ( " plea " ) ; String start = " toon " ; String target = " plea " ; Console . Write ( " Length ▁ of ▁ shortest ▁ chain ▁ is : ▁ " + shortestChainLen ( start , target , D ) ) ; } }
Dynamic Connectivity | Set 1 ( Incremental ) | C # implementation of incremental connectivity ; Finding the root of node i ; union of two nodes a and b ; union based on rank ; Returns true if two nodes have same root ; Performing an operation according to query type ; type 1 query means checking if node x and y are connected or not ; If roots of x and y is same then yes is the answer ; type 2 query refers union of x and y ; If x and y have different roots then union them ; Driver Code ; No . of nodes ; The following two arrays are used to implement disjoint set data structure . arr [ ] holds the parent nodes while rank array holds the rank of subset ; initializing both array and rank ; number of queries
using System ; class GFG { static int root ( int [ ] arr , int i ) { while ( arr [ i ] != i ) { arr [ i ] = arr [ arr [ i ] ] ; i = arr [ i ] ; } return i ; } static void weighted_union ( int [ ] arr , int [ ] rank , int a , int b ) { int root_a = root ( arr , a ) ; int root_b = root ( arr , b ) ; if ( rank [ root_a ] < rank [ root_b ] ) { arr [ root_a ] = arr [ root_b ] ; rank [ root_b ] += rank [ root_a ] ; } else { arr [ root_b ] = arr [ root_a ] ; rank [ root_a ] += rank [ root_b ] ; } } static Boolean areSame ( int [ ] arr , int a , int b ) { return ( root ( arr , a ) == root ( arr , b ) ) ; } static void query ( int type , int x , int y , int [ ] arr , int [ ] rank ) { if ( type == 1 ) { if ( areSame ( arr , x , y ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } else if ( type == 2 ) { if ( areSame ( arr , x , y ) == false ) weighted_union ( arr , rank , x , y ) ; } } public static void Main ( String [ ] args ) { int n = 7 ; int [ ] arr = new int [ n ] ; int [ ] rank = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = i ; rank [ i ] = 1 ; } query ( 1 , 0 , 1 , arr , rank ) ; query ( 2 , 0 , 1 , arr , rank ) ; query ( 2 , 1 , 2 , arr , rank ) ; query ( 1 , 0 , 2 , arr , rank ) ; query ( 2 , 0 , 2 , arr , rank ) ; query ( 2 , 2 , 3 , arr , rank ) ; query ( 2 , 3 , 4 , arr , rank ) ; query ( 1 , 0 , 5 , arr , rank ) ; query ( 2 , 4 , 5 , arr , rank ) ; query ( 2 , 5 , 6 , arr , rank ) ; query ( 1 , 2 , 6 , arr , rank ) ; } }
Ford | C # program for implementation of Ford Fulkerson algorithm ; Number of vertices in graph ; Returns true if there is a path from source ' s ' to sink ' t ' in residual graph . Also fills parent [ ] to store the path ; Create a visited array and mark all vertices as not visited ; Create a queue , enqueue source vertex and mark source vertex as visited ; Standard BFS Loop ; If we find a connection to the sink node , then there is no point in BFS anymore We just have to set its parent and can return true ; We didn 't reach sink in BFS starting from source,  so return false ; Returns tne maximum flow from s to t in the given graph ; Create a residual graph and fill the residual graph with given capacities in the original graph as residual capacities in residual graph Residual graph where rGraph [ i , j ] indicates residual capacity of edge from i to j ( if there is an edge . If rGraph [ i , j ] is 0 , then there is not ) ; This array is filled by BFS and to store path ; There is no flow initially ; Augment the flow while tere is path from source to sink ; Find minimum residual capacity of the edhes along the path filled by BFS . Or we can say find the maximum flow through the path found . ; update residual capacities of the edges and reverse edges along the path ; Add path flow to overall flow ; Return the overall flow ; Driver code ; Let us create a graph shown in the above example
using System ; using System . Collections . Generic ; public class MaxFlow { static readonly int V = 6 ; bool bfs ( int [ , ] rGraph , int s , int t , int [ ] parent ) { bool [ ] visited = new bool [ V ] ; for ( int i = 0 ; i < V ; ++ i ) visited [ i ] = false ; List < int > queue = new List < int > ( ) ; queue . Add ( s ) ; visited [ s ] = true ; parent [ s ] = - 1 ; while ( queue . Count != 0 ) { int u = queue [ 0 ] ; queue . RemoveAt ( 0 ) ; for ( int v = 0 ; v < V ; v ++ ) { if ( visited [ v ] == false && rGraph [ u , v ] > 0 ) { if ( v == t ) { parent [ v ] = u ; return true ; } queue . Add ( v ) ; parent [ v ] = u ; visited [ v ] = true ; } } } return false ; } int fordFulkerson ( int [ , ] graph , int s , int t ) { int u , v ; int [ , ] rGraph = new int [ V , V ] ; for ( u = 0 ; u < V ; u ++ ) for ( v = 0 ; v < V ; v ++ ) rGraph [ u , v ] = graph [ u , v ] ; int [ ] parent = new int [ V ] ; int max_flow = 0 ; while ( bfs ( rGraph , s , t , parent ) ) { int path_flow = int . MaxValue ; for ( v = t ; v != s ; v = parent [ v ] ) { u = parent [ v ] ; path_flow = Math . Min ( path_flow , rGraph [ u , v ] ) ; } for ( v = t ; v != s ; v = parent [ v ] ) { u = parent [ v ] ; rGraph [ u , v ] -= path_flow ; rGraph [ v , u ] += path_flow ; } max_flow += path_flow ; } return max_flow ; } public static void Main ( ) { int [ , ] graph = new int [ , ] { { 0 , 16 , 13 , 0 , 0 , 0 } , { 0 , 0 , 10 , 12 , 0 , 0 } , { 0 , 4 , 0 , 0 , 14 , 0 } , { 0 , 0 , 9 , 0 , 0 , 20 } , { 0 , 0 , 0 , 7 , 0 , 4 } , { 0 , 0 , 0 , 0 , 0 , 0 } } ; MaxFlow m = new MaxFlow ( ) ; Console . WriteLine ( " The ▁ maximum ▁ possible ▁ flow ▁ is ▁ " + m . fordFulkerson ( graph , 0 , 5 ) ) ; } }
Channel Assignment Problem | C # implementation of the above approach ; A Depth First Search based recursive function that returns true if a matching for vertex u is possible ; Try every receiver one by one ; If sender u has packets to send to receiver v and receiver v is not already mapped to any other sender just check if the number of packets is greater than '0' because only one packet can be sent in a time frame anyways ; Mark v as visited ; If receiver ' v ' is not assigned to any sender OR previously assigned sender for receiver v ( which is matchR [ v ] ) has an alternate receiver available . Since v is marked as visited in the above line , matchR [ v ] in the following recursive call will not get receiver ' v ' again ; Returns maximum number of packets that can be sent parallely in 1 time slot from sender to receiver ; An array to keep track of the receivers assigned to the senders . The value of matchR [ i ] is the sender ID assigned to receiver i . The value - 1 indicates nobody is assigned . ; Initially all receivers are not mapped to any senders ; Count of receivers assigned to senders ; Mark all receivers as not seen for next sender ; Find if the sender ' u ' can be assigned to the receiver ; Driver Code
using System ; class GFG { static int M = 3 ; static int N = 3 ; static Boolean bpm ( int [ , ] table , int u , Boolean [ ] seen , int [ ] matchR ) { for ( int v = 0 ; v < N ; v ++ ) { if ( table [ u , v ] > 0 && ! seen [ v ] ) { seen [ v ] = true ; if ( matchR [ v ] < 0 || bpm ( table , matchR [ v ] , seen , matchR ) ) { matchR [ v ] = u ; return true ; } } } return false ; } static int maxBPM ( int [ , ] table ) { int [ ] matchR = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) matchR [ i ] = - 1 ; int result = 0 ; for ( int u = 0 ; u < M ; u ++ ) { Boolean [ ] seen = new Boolean [ N ] ; if ( bpm ( table , u , seen , matchR ) ) result ++ ; } Console . WriteLine ( " The ▁ number ▁ of ▁ maximum ▁ packets " + " ▁ sent ▁ in ▁ the ▁ time ▁ slot ▁ is ▁ " + result ) ; for ( int x = 0 ; x < N ; x ++ ) if ( matchR [ x ] + 1 != 0 ) Console . WriteLine ( " T " + ( matchR [ x ] + 1 ) + " - > ▁ R " + ( x + 1 ) ) ; return result ; } public static void Main ( String [ ] args ) { int [ , ] table = { { 0 , 2 , 0 } , { 3 , 0 , 1 } , { 2 , 4 , 0 } } ; maxBPM ( table ) ; } }
Perfect Binary Tree Specific Level Order Traversal | Set 2 | C # program for special order traversal ; A binary tree node has data , pointer to left child and a pointer to right child ; Function body ; Create a queue and enqueue left and right children of root ; We process two nodes at a time , so we need two variables to store two front items of queue ; traversal loop ; Pop two items from queue ; Push first and second node 's  children in reverse order ; If first and second have grandchildren , enqueue them in specific order ; Given a perfect binary tree , print its nodes in specific level order ; create a stack and push root ; Push level 1 and level 2 nodes in stack ; Since it is perfect Binary Tree , right is not checked ; Do anything more if there are nodes at next level in given perfect Binary Tree ; Finally pop all Nodes from stack and prints them . ; Driver Code
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } class GFG { public Node root ; public virtual void printSpecificLevelOrderUtil ( Node root , Stack < Node > s ) { if ( root == null ) { return ; } LinkedList < Node > q = new LinkedList < Node > ( ) ; q . AddLast ( root . left ) ; q . AddLast ( root . right ) ; Node first = null , second = null ; while ( q . Count > 0 ) { first = q . First . Value ; q . RemoveFirst ( ) ; second = q . First . Value ; q . RemoveFirst ( ) ; s . Push ( second . left ) ; s . Push ( first . right ) ; s . Push ( second . right ) ; s . Push ( first . left ) ; if ( first . left . left != null ) { q . AddLast ( first . right ) ; q . AddLast ( second . left ) ; q . AddLast ( first . left ) ; q . AddLast ( second . right ) ; } } } public virtual void printSpecificLevelOrder ( Node root ) { Stack < Node > s = new Stack < Node > ( ) ; s . Push ( root ) ; if ( root . left != null ) { s . Push ( root . right ) ; s . Push ( root . left ) ; } if ( root . left . left != null ) { printSpecificLevelOrderUtil ( root , s ) ; } while ( s . Count > 0 ) { Console . Write ( s . Peek ( ) . data + " ▁ " ) ; s . Pop ( ) ; } } public static void Main ( string [ ] args ) { GFG tree = new GFG ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; Console . WriteLine ( " Specific ▁ Level ▁ Order ▁ Traversal ▁ " + " of ▁ Binary ▁ Tree ▁ is ▁ " ) ; tree . printSpecificLevelOrder ( tree . root ) ; }
Prim 's algorithm using priority_queue in STL | If v is not in MST and weight of ( u , v ) is smaller than current key of v ; Updating key of v
if ( inMST [ v ] == false && key [ v ] > weight ) { key [ v ] = weight ; pq . Add ( new Tuple < int , int > ( key [ v ] , v ) ) ; parent [ v ] = u ; }