My Report

Data Structure II Mock Test 6


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement
 10%

Question 1 of 10

1. In general, which of the following methods isn’t used to find the factorial of a number?

Question 1 of 10

Question 2 of 10

2. What is the following expression, lcm (a, gcd (a, b)) equal to?

Question 2 of 10

Question 3 of 10

3. Consider the following recursive implementation to find the factorial of a number. Which of the lines is the base case?

int fact(int n)
{
     if(n == 0)
        return 1;
     return n * fact(n - 1);
}
int main()
{
      int n = 5;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Question 3 of 10

Question 4 of 10

4. What is the time complexity of the fastest known matrix multiplication algorithm?

Question 4 of 10

Question 5 of 10

5. What is the output of the following code?

#include<stdio.h>
#include<stdlib.h>
struct Node
{
      int val;
      struct Node *next;
}*head;
int get_len()
{
      struct Node *temp = head->next;
      int len = 0;
      while(temp != 0)
      {
          len++;
          temp = temp->next;
      }
      return len;
}
int main()
{
      int arr[10] = {1,2,3,4,5}, n = 5, i;
      struct Node *temp, *newNode;
      head = (struct Node*)malloc(sizeof(struct Node));
      head->next = 0;
      temp = head;
      for(i=0; i<n; i++)
      {
          newNode = (struct Node*)malloc(sizeof(struct Node));
          newNode->val = arr[i];
          newNode->next = 0;
          temp->next = newNode;
          temp = temp->next;
      }
      int len = get_len();
      printf("%d",len);
      return 0;
}

Question 5 of 10

Question 6 of 10

6. Which of the following takes O(n) time in worst case in array implementation of stack?

Question 6 of 10

Question 7 of 10

7. Which is the smallest number of 3 digits that is divisible by 2, 4, 8?

Question 7 of 10

Question 8 of 10

8. How many times will the function fact() be called when the following code is executed?

 
int fact(int n)
{
      if(n == 0)
        return 1;
      return n * fact(n - 1);
}
int main()
{
      int n = 5;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Question 8 of 10

Question 9 of 10

9. Which of the following is not another name for GCD(Greatest Common Divisor)?

Question 9 of 10

Question 10 of 10

10. Which of the following methods used to find the sum of first n natural numbers has the least time complexity?

Question 10 of 10


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.