Q.1.
Given a string, you have to find the minimum number of characters to be inserted in the string so that the string becomes a palindrome. Which of the following methods can be used to solve the problem?
Q.2.
In which of the following cases the minimum no of insertions to form palindrome is maximum?
Q.3.
In the worst case, the minimum number of insertions to be made to convert the string into a palindrome is equal to the length of the string.
Q.4.
Consider the string “efge”. What is the minimum number of insertions required to make the string a palindrome?
Q.5.
Consider the string “abbccbba”. What is the minimum number of insertions required to make the string a palindrome?
Q.6.
Which of the following problems can be used to solve the minimum number of insertions to form a palindrome problem?
Q.7.
Consider the following dynamic programming implementation: #include<stdio.h> #include<string.h> int max(int a, int b) { if(a > b) return a; return b; } int min_ins(char *s) { int len = strlen(s), i, j; int arr[len + 1][len + 1]; char rev[len + 1]; strcpy(rev, s); strrev(rev); for(i = 0;i <= len; i++) arr[i][= for(i =i <= len; i++) arr[0][i] = for(i =i <= len; i++) { for(j =j <= len; j++) { if(s[i -== rev[j - 1]) arr[i][j] = arr[i - 1][j -+ else arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]); } } return _____________; } int main() { char s[] = "abcda"; int ans = min_ins(s); printf("%d",ans); return}
Q.8.
What is the time complexity of the following dynamic programming implementation of the minimum number of insertions to form a palindrome problem? #include<stdio.h> #include<string.h> int max(int a, int b) { if(a > b) return a; return b; } int min_ins(char *s) { int len = strlen(s), i, j; int arr[len + 1][len + 1]; char rev[len + 1]; strcpy(rev, s); strrev(rev); for(i = 0;i <= len; i++) arr[i][= for(i =i <= len; i++) arr[0][i] = for(i =i <= len; i++) { for(j =j <= len; j++) { if(s[i -== rev[j - 1]) arr[i][j] = arr[i - 1][j -+ else arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]); } } return len - arr[len][len]; } int main() { char s[] = "abcda"; int ans = min_ins(s); printf("%d",ans); return}
Q.9.
What is the space complexity of the following dynamic programming implementation of the minimum number of insertions to form a palindrome problem? #include<stdio.h> #include<string.h> int max(int a, int b) { if(a > b) return a; return b; } int min_ins(char *s) { int len = strlen(s), i, j; int arr[len + 1][len + 1]; char rev[len + 1]; strcpy(rev, s); strrev(rev); for(i = 0;i <= len; i++) arr[i][= for(i =i <= len; i++) arr[0][i] = for(i =i <= len; i++) { for(j =j <= len; j++) { if(s[i -== rev[j - 1]) arr[i][j] = arr[i - 1][j -+ else arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]); } } return len - arr[len][len]; } int main() { char s[] = "abcda"; int ans = min_ins(s); printf("%d",ans); return}
Q.10.
What is the output of the following code? #include<stdio.h> #include<string.h> int max(int a, int b) { if(a > b) return a; return b; } int min_ins(char *s) { int len = strlen(s), i, j; int arr[len + 1][len + 1]; char rev[len + 1]; strcpy(rev, s); strrev(rev); for(i = 0;i <= len; i++) arr[i][= for(i =i <= len; i++) arr[0][i] = for(i =i <= len; i++) { for(j =j <= len; j++) { if(s[i -== rev[j - 1]) arr[i][j] = arr[i - 1][j -+ else arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]); } } return len - arr[len][len]; } int main() { char s[] = "abcda"; int ans = min_ins(s); printf("%d",ans); return}
Q.11.
What is the value stored in arr[2][when the following code is executed? #include<stdio.h> #include<string.h> int max(int a, int b) { if(a > b) return a; return b; } int min_ins(char *s) { int len = strlen(s), i, j; int arr[len + 1][len + 1]; char rev[len + 1]; strcpy(rev, s); strrev(rev); for(i = 0;i <= len; i++) arr[i][= for(i =i <= len; i++) arr[0][i] = for(i =i <= len; i++) { for(j =j <= len; j++) { if(s[i -== rev[j - 1]) arr[i][j] = arr[i - 1][j -+ else arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]); } } return len - arr[len][len]; } int main() { char s[] = "abcda"; int ans = min_ins(s); printf("%d",ans); return}
Q.12.
What is the output of the following code? #include<stdio.h> #include<string.h> int max(int a, int b) { if(a > b) return a; return b; } int min_ins(char *s) { int len = strlen(s), i, j; int arr[len + 1][len + 1]; char rev[len + 1]; strcpy(rev, s); strrev(rev); for(i = 0;i <= len; i++) arr[i][= for(i =i <= len; i++) arr[0][i] = for(i =i <= len; i++) { for(j =j <= len; j++) { if(s[i -== rev[j - 1]) arr[i][j] = arr[i - 1][j -+ else arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]); } } return len - arr[len][len]; } int main() { char s[] = "efgfe"; int ans = min_ins(s); printf("%d",ans); return}