What is the output of the following C program?
When does the ArrayIndexOutOfBoundsException occur?
Which of the following standard algorithms is not a Greedy algorithm?
1) The degree of the root node is always zero.
2) Nodes that are not the root and not leaf nodes are called internal nodes.
Consider an array of length 5, arr[5] = {8, 6, 3, 2, 1}. What are the steps of the insertion sort algorithm when applied to this array?
What is the space complexity of the following recursive implementation to find the nth Fibonacci number?
int fibo(int n)
{
if (n == 1)
return 0;
else if (n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
int main()
{
int n = 5;
int ans = fibo(n);
printf("%d", ans);
return 0;
}
Consider the following iterative implementation to find the length of the string:
#include<stdio.h>
int get_len(char *s)
{
int len = 0;
while(s[len] != '\0')
len++;
return len;
}
int main()
{
char *s = "harsh";
int len = get_len(s);
printf("%d",len);
return 0;
}
Consider the following iterative implementation to find the nth Fibonacci number:
int main()
{
int n = 10, i;
if(n == 1)
printf("0");
else if(n == 2)
printf("1");
else
{
int x = 0, y = 1, z;
for(i = 3; i <= n; i++)
{
z = x + y;
x = y;
y = z;
}
printf("%d",z);
}
return 0;
}
Which of the following lines should be added to complete the above code?
Which of the following functions correctly represents the solution to the Tower of Hanoi puzzle?
Consider the following dynamic programming implementation of the longest common subsequence problem:
#include<stdio.h>
#include<string.h>
int max_num(int x, int y)
{
if(x > y)
return x;
return y;
}
int lcs(char *str1, char *str2)
{
int m,n,len1,len2;
len1 = strlen(str1);
len2 = strlen(str2);
int arr[len1 + 1][len2 + 1];
for(m = 0; m <= len1; m++)
arr[m][0] = 0;
for(m = 0; m <= len2; m++)
arr[0][m] = 0;
for(m = 1; m <= len1; m++)
{
for(n = 1; n <= len2; n++)
{
if(str1[m-1] == str2[n - 1])
arr[m][n] = 1 + arr[m - 1][n - 1];
else
arr[m][n] = max_num(arr[m - 1][n], arr[m][n - 1]);
}
}
return arr[len1][len2];
}
int main()
{
char str1[] = "abcedfg", str2[] = "bcdfh";
int ans = lcs(str1,str2);
printf("%d",ans);
return 0;
}
Which of the following lines completes the above code?
OnSite
1 Openings
FullTime
Posted 17 days ago