Vidyalelo
Data Structure · all questions

Miscellaneous on Data Structures
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

1,171

Questions

8/59

Page

Pick an option on a question to see the right answer and solution.

How many unique colors will be required for proper vertex coloring of a line graph having n vertices?

Select an option to see the answer and solution.

A dominating set of graph G, is the subset D of vertices, if each vertex not in D is adjacent to how many vertices?

Select an option to see the answer and solution.

Which of the following lines should be inserted to complete the following recursive implementation used to find the length of a linked list?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
      int val;
      struct Node *next;
}*head;
int recursive_get_len(struct Node *current_node)
{
      if(current_node == 0)
        return 0;
      return _____;
}
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 = recursive_get_len(head->next);
      printf("%d",len);
      return 0;
}

Select an option to see the answer and solution.

What is the output of the following code?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return n % 10 + recursive_sum_of_digits(n/10);
}
int main()
{
      int n = 10000;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Select an option to see the answer and solution.

What will be the plain text corresponding to ciphered text "134325" if standard polybius square cipher is used for encryption?

Select an option to see the answer and solution.

What is the running time of Strassen's algorithm for matrix multiplication?

Select an option to see the answer and solution.

What will be output for the given code taking input string as "example"?
package com.example.setandstring;
import java.util.Scanner;
public class MonoalphabeticCipher
{
      public static char p[]  = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
                                  'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
                                  'u', 'v', 'w', 'x', 'y', 'z' };
      public static char ch[] = { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
                                  'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z',
                                  'X', 'C', 'V', 'B', 'N', 'M' };
      public static String doEncryption(String s)
      { 
           char c[] = new char[(s.length())];
           for (int i = 0; i < s.length(); i++)
           {
                for (int j = 0; j < 26; j++)
                { 
                     if (p[j] == s.charAt(i))
                     {
                         c[i] = ch[j];
                          break;
                     }
                }
            }  return (new String(c));
        }   
        public static void main(String args[])
        {
             Scanner sc = new Scanner(System.in);
             System.out.println("Enter the message: ");
             String en = doEncryption(sc.next().toLowerCase());
             System.out.println("Encrypted message: " + en);
             sc.close();
         }
}

Select an option to see the answer and solution.

What is the GCD of 48, 18, 0?

Select an option to see the answer and solution.

To which of the following class does a CNF-satisfiability problem belong?

Select an option to see the answer and solution.

What will be the ciphered text if the string "EXAMPLE" is given as input to the code of vigenere cipher with keyword as "HELLO"?

Select an option to see the answer and solution.

What is the output of the following code?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int get_max()
{
      struct Node* temp = head->next;
	  int max_num = temp->val;
	  while(temp != 0)
	  {
	        if(temp->val > max_num)
		    max_num = temp->val;
		temp = temp->next;
	  }
	  return max_num;
}
int get_min()
{
      struct Node* temp = head->next;
	  int min_num = temp->val;
	  while(temp != 0)
	  {
	        if(temp->val < min_num)
		    min_num = temp->val;
		temp = temp->next;
	  }
	  return min_num;
}
int main()
{
      int i, n = 9, arr[9] ={8,3,3,4,5,2,5,6,7};
      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->next = 0;
          newNode->val = arr[i];
          temp->next =newNode;
          temp = temp->next;
      }
      int max_num = get_max();
      int min_num = get_min();
      printf("%d %d",max_num,min_num);
      return 0;
}

Select an option to see the answer and solution.

What will be the chromatic number for an empty graph having n vertices?

Select an option to see the answer and solution.

Heap's algorithm requires an auxiliary array to create permutations.

Select an option to see the answer and solution.

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;
}

Select an option to see the answer and solution.

Which of the following algorithm can be used to solve the Hamiltonian path problem efficiently?

Select an option to see the answer and solution.

Is lcm an associative function.

Select an option to see the answer and solution.

What will be the time complexity of the given code?
#include <stdio.h> 
#include <string.h> 
#include <iostream.h>
using namespace std;
void swap(char *x, char *y) 
{ 
	char temp; 
	temp = *x; 
	*x = *y; 
	*y = temp; 
} 
 
void func(char *a, int l, int r) 
{ 
int i; 
if (l == r) 
	cout<<a<<” ,”; 
else
{ 
	for (i = l; i <= r; i++) 
	{ 
		swap((a+l), (a+i)); 
		func(a, l+1, r); 
		swap((a+l), (a+i)); 
	} 
} 
} 
 
int main() 
{ 
	char str[] = "AB"; 
	int n = strlen(str); 
	func(str, 0, n-1); 
	return 0; 
}

Select an option to see the answer and solution.

Square root decomposition technique is only applicable when the number of indices in an array is a perfect square.

Select an option to see the answer and solution.

What is the minimum dominating set of the binary tree given below?
Miscellaneous on Data Structures mcq question image

Select an option to see the answer and solution.

Given below is the pseudocode of floyd's cycle detection algorithm. Which of the following best suits the blank?
Start traversing the linked list using two pointers
move one pointer with . . . . . . . .
if pointers meet at any node
{
    loop exists in the linked list 
}
else 
{
    linked list doesn’t have a loop
}

Select an option to see the answer and solution.