Problem Statement : - Given two strings str1 and str2 and below operations that can performed on str1. Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’. Operations and their Cost which we can perform to achieve this goal Insert - 1 Delete - 1 Replace - 2 (Note : Delete The Element + Insert New Element) Example 1 : - Input : s1= Hogward , s2= Hogwartz Output : 4 E xplanation : 1. Insert 'g' at index 3 ; cost = 1 2. Replace 'd' with 't' at index 7; cost = 2 3. Insert 'z' at index 8 = 1; cost=1 Total cost = 1+2+1 = 4 Idea : - We create array MED of Size M * N where M= length of s1 N= length of s2 To Solve This Problem We use Dynamic Approach. We solve All sub problem which is |sub1|=m , |sub2|=n where m <=|s1| and n<=|s2| If last characters of two strings are same, nothing need to do. So we use Previous Solution and Recur for...
Problem :- The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. For example, following is a solution for 4 Queen problem. Idea:- Place the queens column wise, start from the left most column If all queens are placed. return true and print the solution matrix. Else Try all the rows in the current column. Check if queen can be placed here safely if yes mark the current cell in solution matrix as 1 and try to solve the rest of the problem recursively. If placing the queen in above step leads to the solution return true. If placing the queen in above step does not lead to the solution , BACKTRACK, mark the current cell in solution matrix as 0 and return false. If all the rows are tried and nothing worked, return false and print NO SOLUTION. Algo :- NQueen(k,n) { for(i=1 to n) do { if(place(k,i)) then { x[k]=i; if(k==n) then write (x[1:n])...