human
Give me a code to minimum insertions to form a palindrome and the other steps required given the following:
Minimum insertions to form a palindrome | DP | A utility function to find minimum of two integers.
A DP function to find minimum number of insertions.
Create a table of size n * n . table [ i ] [ j ] will store minimum number of insertions needed to convert str1 [ i . . j ] to a palindrome ..
Fill the table.
Return minimum number of insertions for str1 [ 0. . n - 1 ].
Driver Code"
Solution in Python:
assistant
#Here is code to minimum insertions to form a palindrome and the other steps required.
 def Min ( a , b ) :
	return min ( a , b )
def findMinInsertionsDP ( str1 , n ) :
	table = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
	l , h , gap = 0 , 0 , 0
	for gap in range ( 1 , n ) :
		l = 0
		for h in range ( gap , n ) :
			if str1 [ l ] == str1 [ h ] :
				table [ l ] [ h ] = table [ l + 1 ] [ h - 1 ]
			else :
				table [ l ] [ h ] = ( Min ( table [ l ] [ h - 1 ] , table [ l + 1 ] [ h ] ) + 1 )
			l += 1
	return table [ 0 ] [ n - 1 ] ;
str1 = " geeks "
print ( findMinInsertionsDP ( str1 , len ( str1 ) ) )