human
Prufer Code to Tree Creation | Prints edges of tree represented by give Prufer code.
Initialize the array of vertices.
Number of occurrences of vertex in code.
Find the smallest label not present in prufer ..
If j + 1 is not present in prufer set.
Remove from Prufer set and print pair ..
For the last element.
Driver code"
How can the above be solved in Python?
 ... What is a code to prufer Code to Tree Creation and the other steps required?
assistant
#Here is code to prufer Code to Tree Creation and the other steps required.
 def printTreeEdges ( prufer , m ) :
	vertices = m + 2
	vertex_set = [ 0 ] * vertices
	for i in range ( vertices - 2 ) :
		vertex_set [ prufer [ i ] - 1 ] += 1
	print ( " The ▁ edge ▁ set ▁ E ( G ) ▁ is ▁ : " )
	j = 0
	for i in range ( vertices - 2 ) :
		for j in range ( vertices ) :
			if ( vertex_set [ j ] == 0 ) :
				vertex_set [ j ] = - 1
				print ( " ( " , ( j + 1 ) , " , ▁ " , prufer [ i ] , " ) ▁ " , sep = " " , end = " " )
				vertex_set [ prufer [ i ] - 1 ] -= 1
				break
	j = 0
	for i in range ( vertices ) :
		if ( vertex_set [ i ] == 0 and j == 0 ) :
			print ( " ( " , ( i + 1 ) , " , ▁ " , sep = " " , end = " " )
			j += 1
		elif ( vertex_set [ i ] == 0 and j == 1 ) :
			print ( ( i + 1 ) , " ) " )
prufer = [ 4 , 1 , 3 , 4 ]
n = len ( prufer )
printTreeEdges ( prufer , n )