Saturday, October 10, 2020

Analysis and Design of Algorithms Multiple choice questions

 1.Recursion is similar to which of the following?
 Switch Case
 Loop
 If-else
 if elif else

2.In recursion, the condition for which the function will stop calling itself is ____________
 Best case
 Worst case
 Base case
 There is no such condition

3.Consider the following code snippet:
void my_recursive_function()
{
my_recursive_function();
}
int main()
{
my_recursive_function();
return 0;
}

What will happen when the above snippet is executed?
 The code will be executed successfully and no output will be generated
 The code will be executed successfully and random output will be generated
 The code will show a compile-time error
 The code will run for some time and stop when the stack overflows

4.What is the output of the following code?
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}
 10
 1
 10 9 8 ... 1 0
 10 9 8 ... 1

5.What is the base case for the following code?
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}

 Return
 printf(“%d “, n)
 if(n == 0)
 My_recursive_function(n-1)

6.How many times is the recursive function called, when the following code is executed?
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}

 9
 10
 11
 12

7.Which of the following statements is true?
 Recursion is always better than iteration
 Recursion uses more memory compared to iteration
 Recursion uses less memory compared to iteration
 Iteration is always better and simpler than recursion

8.What will be the output of the following code?
int cnt=0;
void my_recursive_function(int n)
{
if(n == 0)
return;
cnt++;
my_recursive_function(n/10);
}
int main()
{
my_recursive_function(123456789);
printf("%d",cnt);
return 0;
}

 123456789
 10
 0
 9

9.
void my_recursive_function(int n)
{
if(n == 0)
{
printf("False");
return;
}
if(n == 1)
{
printf("True");
return;
}
if(n%2==0)
my_recursive_function(n/2);
else
{
printf("False");
return;
}
}
int main()
{
my_recursive_function(100);
return 0;
}

 True
 False

10.What is the output of the following code?
int cnt = 0;
void my_recursive_function(char *s, int i)
{
if(s[i] == '\0')
return;
if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')
cnt++;
my_recursive_function(s,i+1);
}
int main()
{
my_recursive_function("thisisrecursion",0);
printf("%d",cnt);
return 0;
}

 6
 9
 5
 10

11.What is the output of the following code?
void my_recursive_function(int *arr, int val, int idx, int len)
{
if(idx == len)
{
printf("-1");
return ;
}
if(arr[idx] == val)
{
printf("%d",idx);
return;
}
my_recursive_function(arr,val,idx+1,len);
}
int main()
{
int array[10] = {7, 6, 4, 3, 2, 1, 9, 5, 0, 8};
int value = 2;
int len = 10;
my_recursive_function(array, value, 0, len);
return 0;
}

 3
 4
 5
 6

12.______is the first step in solving the problem
 Understanding the Problem
 Identify the Problem
 Evaluate the Solution
 None of these

13.______is the last step in solving the problem
 Understanding the Problem
 Identify the Problem
 Evaluate the Solution
 None of these

14.Following is true for understanding of a problem
 Knowing the knowledgebase
 Understanding the subject on which the problem is based
 Communication with the client
 All of the above

15.The six-step solution for the problem can be applied to
I. Problems with Algorithmic Solution
II. Problems with Heuristic Solution
 Only I
 Only II
 Both I and II
 Neither I nor II

16.______ solution requires reasoning built on knowledge and experience
 Algorithmic Solution
 Heuristic Solution
 Random Solution
 None of these

17.The correctness and appropriateness of ___________solution can be checked very easily.
 Algorithmic solution
 Heuristic solution
 Random solution
 None of these

18.The branch of computer that deals with heuristic types of problem is called _________________.
 System software
 Real time software
 Artificial intelligence
 None of these

19.Artificial Intelligence makes use of following prominently
 Database
 Data Warehouse
 Knowledge base
 None of these

20.Naming convention for variable is followed in company because ____________.
 It enhances readability
 It allows to work without conflicts
 It enhances the efficiency
 All of the above

No comments:

Post a Comment

Open Researcher and Contributor ID (ORCID)

Search Aptipedia