Home / MCQ Bank / Computer
Computer Dynamic Programming In Data Structures

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][0] = 0; for(i = 0; i <= len; i++) arr[0][i] = 0; for(i = 1; i <= len; i++) { for(j = 1; j <= len; j++) { if(s[i - 1] == rev[j - 1]) arr[i][j] = arr[i - 1][j - 1] + 1; 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 0; }

Select the best option to verify your answer:
Show Correct Answer
Correct Answer: Option C • O(n 2 )

Related Computer Questions

What will the following script output? <?php $time = strtotime ( '2004/01/01' ) ; echo date ( 'H:i:s', $time ) ; ?> What will be the output of the following Java program? class Output { public static void main(String args[]) { double x = 3.14; int y = (int) Math.toDegrees(x); System.out.print(y); } } Which of the following keyboard shortcuts is used to add a bookmark of the page currently opened in a Chrome browser? Determine Output: void main() { struct xx { int x=3; char name[] = "hello"; }; struct xx *s = malloc(sizeof(struct xx)); printf("%d", s->x); printf("%s", s->name); } Which of the following field properties is an expression that specifies criteria or requirements for entering data?