Question:
What is the correct postfix expression for the following expression?
a+b*(c^d-e)^(f+g*h)-i

Choices:
- abc^de-fg+*^*+i-
- abcde^-fg*+*^h*+i-
- abcd^e-fgh*+^*+i-
- ab^-dc*+ef^gh*+i-


Question:
What would be the solution to the given prefix notation?
- + 5 / 10 5 5

Choices:
- 2
- 5
- 10
- 7


Question:
What would be the solution to the given prefix notation?
/ / / / 16 4 2 1

Choices:
- 1
- 4
- 2
- 8


Question:
What would be the solution to the given prefix notation?
+ 9 * 3 / 8 4

Choices:
- 14
- 15
- 18
- 12


Question:
What would be the solution to the given prefix notation?
- + 1 2 * 3 / 6 2

Choices:
- 6
- -6
- 3
- -3


Question:
What would be the solution to the given prefix notation?
- * 1 5 / * / 6 3 6 2

Choices:
- 1
- 0
- -1
- -2


Question:
What would be the solution to the given prefix notation?
* / + 1 2 / 4 2 + 3 5

Choices:
- 12
- 7.5
- 9
- 13.5


Question:
Find the error (if any) in the following code snippet for pop operation.
void pop() //removing an element from a stack
{
     printf(“%s”, stack[top++]);
}

Choices:
- run time error
- compile time error
- pop operation is performed, but top moved in wrong direction
- pop operation is performed properly


Question:
What will be the output of the following program?
main()
{
   char str[]="san foundry";
   int len = strlen(str);
   int i;

   for(i=0;i<len;i++)
        push(str[i]);  // pushes an element into stack

   for(i=0;i<len;i++)
      pop();  //pops an element from the stack
}

Choices:
- sanfoundry
- san foundry
- yrdnuof nas
- foundry nas


Question:
What is the functionality of the following piece of code?
public Object function(int row_index, int col_index)
{
        if (row_index < 0 || col_index > N)
	{
            System.out.println("column index out of bounds");
			return;
	}
        return (sparse_array[row_index].fetch(col_index));
}

Choices:
- Store the element in the specified position
- Get the element from the specified position
- Alter the element in the specified position
- Removes the element from the specified position


Question:
What does the following piece of code do?
for(int i = 0; i < row; i++)
{
    for(int j = 0; j < column; j++)
    {
        if(i == j)
            sum = sum + (array[i][j]);
    }
}
System.out.println(sum);

Choices:
- Normal of a matrix
- Trace of a matrix
- Square of a matrix
- Transpose of a matrix


Question:
What is the time complexity of the following code that determines the number of inversions in an array?
int InvCount(int arr[], int n)
{
	int count = 0;
	for (int i = 0; i < n - 1; i++)
		for (int j = i + 1; j < n; j++)
			if (arr[i] > arr[j])
				count++;

	return count;
}

Choices:
- O(n)
- O(n log n)
- O(n2)
- O(log n)


Question:
What will be the output of the following code?
#include <iostream>
using namespace std;
int main()
{
    int arr[] = {1,2,3,4,5,6};
    int n = sizeof(arr)/sizeof(arr[0]);
    int d=4;
    int temp[10];

    for(int i=0;i<d;i++)
    temp[i]=arr[i];

    int j=0;
    for(int i=d;i<n;i++,j++)
    arr[j]=arr[i];

    int k=0;
    for(int i=n-d;i<n;i++,k++)
    arr[i]=temp[k];

    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    return 0;
}

Choices:
- 5 6 1 2 3 4
- 6 5 4 3 1 2
- 3 4 5 6 1 2
- error


Question:
What will be the time complexity of the following code?
#include <iostream>
using namespace std;
int main()
{
    int arr[] = {1,2,3,4,5,6};
    int n = sizeof(arr)/sizeof(arr[0]);
    int d=4;
    int temp[10];

    for(int i=0;i<d;i++)
    temp[i]=arr[i];

    int j=0;
    for(int i=d;i<n;i++,j++)
    arr[j]=arr[i];

    int k=0;
    for(int i=n-d;i<n;i++,k++)
    arr[i]=temp[k];

    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    return 0;
}

Choices:
- O(d)
- O(n)
- O(n2)
- O(n*d)


Question:
What will be the auxiliary space complexity of the following code?
#include <iostream>
using namespace std;
int main()
{
    int arr[] = {1,2,3,4,5,6};
    int n = sizeof(arr)/sizeof(arr[0]);
    int d=4;
    int temp[10];

    for(int i=0;i<d;i++)
    temp[i]=arr[i];

    int j=0;
    for(int i=d;i<n;i++,j++)
    arr[j]=arr[i];

    int k=0;
    for(int i=n-d;i<n;i++,k++)
    arr[i]=temp[k];

    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    return 0;
}

Choices:
- O(1)
- O(n)
- O(d)
- O(n*d)


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;

void func1(int arr[], int n)
{
	int k = arr[0], i;
	for (i = 0; i < n - 1; i++)
		arr[i] = arr[i + 1];

	arr[i] = k;
}

void func(int arr[], int d, int n)
{
	for (int i = 0; i < d; i++)
		func1(arr, n);
}

void printArray(int arr[], int n)
{
	for (int i = 0; i < n; i++)
		cout << arr[i] << " ";
}

int main()
{
	int arr[] = { 1, 2, 3, 4, 5};
	int n = sizeof(arr) / sizeof(arr[0]);

	func(arr, 3, n);
	printArray(arr, n);

	return 0;
}

Choices:
- 4 5 1 2 3
- 3 4 5 1 2
- 5 4 3 1 2
- error


Question:
What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void func1(int arr[], int n)
{
	int k = arr[0], i;
	for (i = 0; i < n - 1; i++)
		arr[i] = arr[i + 1];

	arr[i] = k;
}

void func(int arr[], int d, int n)
{
	for (int i = 0; i < d; i++)
		func1(arr, n);
}

void printArray(int arr[], int n)
{
	for (int i = 0; i < n; i++)
		cout << arr[i] << " ";
}

int main()
{
	int arr[] = { 1, 2, 3, 4, 5};
	int n = sizeof(arr) / sizeof(arr[0]);

    int d = 3;
	func(arr, d, n);
	printArray(arr, n);

	return 0;
}

Choices:
- O(n*d)
- O(n)
- O(d)
- O(n2)


Question:
What will be the auxiliary space complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void func1(int arr[], int n)
{
	int k = arr[0], i;
	for (i = 0; i < n - 1; i++)
		arr[i] = arr[i + 1];

	arr[i] = k;
}

void func(int arr[], int d, int n)
{
	for (int i = 0; i < d; i++)
		func1(arr, n);
}

void printArray(int arr[], int n)
{
	for (int i = 0; i < n; i++)
		cout << arr[i] << " ";
}

int main()
{
	int arr[] = { 1, 2, 3, 4, 5};
	int n = sizeof(arr) / sizeof(arr[0]);

    int d = 3;
	func(arr, d, n);
	printArray(arr, n);

	return 0;
}

Choices:
- O(1)
- O(n)
- O(d)
- O(n*d)


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;
void func1(int arr[], int left, int right)
{
	while (left < right)
	{
		int temp = arr[left];
		arr[left] = arr[right];
		arr[right] = temp;
		left++;
		right--;
	}
}

void func(int arr[], int d, int n)
{
	func1(arr, 0, d-1);
	func1(arr, d, n-1);
	func1(arr, 0, n-1);
}

void printArray(int arr[], int size)
{
	for (int i = 0; i < size; i++)
	cout << arr[i] << " ";
}

int main()
{
	int arr[] = {1, 2, 3, 4, 5};
	int n = sizeof(arr)/sizeof(arr[0]);
	int d = 2;
	func(arr, d, n);
	printArray(arr, n);

	return 0;
}

Choices:
- 3 2 1 4 5
- 3 4 5 1 2
- 5 4 3 2 1
- error


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;

void func(int arr[], int left, int right)
{
	while (left < right)
	{
		int temp = arr[left];
		arr[left] = arr[right];
		arr[right] = temp;
		left++;
		right--;
	}

}

void printArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    cout << arr[i] << " ";
}

int main()
{
	int arr[] = {1,4,3,5};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, 0, n-1);
	printArray(arr, n);
	return 0;
}

Choices:
- 5 1 4 3
- 3 5 1 4
- 5 3 4 1
- error


Question:
What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int arr[], int left, int right)
{
    	while (left < right)
	{
		int temp = arr[left];
		arr[left] = arr[right];
		arr[right] = temp;
		left++;
		right--;
	}

}

void printArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    cout << arr[i] << " ";
}

int main()
{
	int arr[] = {1,4,3,5};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, 0, n-1);
	printArray(arr, n);
	return 0;
}

Choices:
- O(n)
- O(log n)
- O(1)
- O(n log n)


Question:
What will be the auxiliary space requirement of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int arr[], int left, int right)
{
	while (left < right)
	{
		int temp = arr[left];
		arr[left] = arr[right];
		arr[right] = temp;
		left++;
		right--;
	}

}

void printArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    cout << arr[i] << " ";
}

int main()
{
	int arr[] = {1,4,3,5};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, 0, n-1);
	printArray(arr, n);
	return 0;
}

Choices:
- O(1)
- O(n)
- O(log n)
- O(n log n)


Question:
What will be the output of the following code ?
#include <bits/stdc++.h>
using namespace std;

void func(int arr[], int left, int right)
{
    if (left >= right)
    return;

    int temp = arr[left];
    arr[left] = arr[right];
    arr[right] = temp;

    func(arr, left + 1, right - 1);
}

void printArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    cout << arr[i] << " ";
}

int main()
{
	int arr[] = {1,2,3,4};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, 0, n-1);
	printArray(arr, n);
	return 0;
}

Choices:
- 1 2 3 4
- 4 3 2 1
- 1 4 2 3
- 4 1 2 3


Question:
What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int arr[], int left, int right)
{
    if (left >= right)
    return;

    int temp = arr[left];
    arr[left] = arr[right];
    arr[right] = temp;

    func(arr, left + 1, right - 1);
}

void printArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    cout << arr[i] << " ";
}

int main()
{
	int arr[] = {1,2,3,4};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, 0, n-1);
	printArray(arr, n);
	return 0;
}

Choices:
- O(1)
- O(n)
- O(log n)
- O(n log n)


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int a[], int n, int k)
{
	if (k <= n)
	{
		for (int i = 0; i < k/2; i++)
		swap(a[i], a[k-i-1]);
	}

}
int main()
{
	int a[] = {1, 2, 3, 4, 5};
	int n = sizeof(a) / sizeof(int), k = 3;
	func(a, n, k);
	for (int i = 0; i < n; ++i)
		cout << a[i]<<" ";
	return 0;
}

Choices:
- 3 2 1 4 5
- 5 4 3 2 1
- 1 2 5 4 3
- error


Question:
What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;

void func(int a[], int n, int k)
{
	if (k <= n)
	{
		for (int i = 0; i < k/2; i++)
		swap(a[i], a[k-i-1]);
	}

}
int main()
{
	int a[] = {1, 2, 3, 4, 5};
	int n = sizeof(a) / sizeof(int), k = 3;
	func(a, n, k);
	for (int i = 0; i < n; ++i)
		cout << a[i]<<" ";
	return 0;
}

Choices:
- O(k)
- O(n)
- O(k log k)
- O(n log n)


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;

int func(int arr[], int s, int e)
{
   if (s == e)
	return 0;
   if (arr[s] == 0)
	return INT_MAX;

int min = INT_MAX;
for (int i = s + 1; i <= e && i <= s + arr[s]; i++)
{
	int jumps = func(arr, i, e);
	if(jumps != INT_MAX && jumps + 1 < min)
		min = jumps + 1;
}
return min;
}

int main()
{
	int arr[] = {1, 3, 6, 3, 8, 5};
	int n = sizeof(arr)/sizeof(arr[0]);
	cout << func(arr, 0, n-1);
	return 0;
}

Choices:
- 1
- 2
- 3
- error


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;

int min(int x, int y)
{ return (x < y)? x: y; }

int func(int arr[], int n)
{

	int *jump = new int[n];
	int i, j;

	if (n == 0 || arr[0] == 0)
		return INT_MAX;

	jump[0] = 0;

	for (i = 1; i < n; i++)
	{
		jump[i] = INT_MAX;
		for (j = 0; j < i; j++)
		{
			if (i <= j + arr[j] && jumps[j] != INT_MAX)
			{
				jump[i] = min(jump[i], jump[j] + 1);
				break;
			}
		}
	}
	return jump[n-1];
}

int main()
{
	int arr[] = {1, 3, 6, 1, 9,7};
	int size = sizeof(arr)/sizeof(int);
	cout<< func(arr,size);
	return 0;
}

Choices:
- 1
- 2
- 3
- error


Question:
What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;

int min(int x, int y)
{ return (x < y)? x: y; }

int func(int arr[], int n)
{

	int *jump = new int[n];
	int i, j;

	if (n == 0 || arr[0] == 0)
		return INT_MAX;

	jump[0] = 0;

	for (i = 1; i < n; i++)
	{
		jump[i] = INT_MAX;
		for (j = 0; j < i; j++)
		{
			if (i <= j + arr[j] && jumps[j] != INT_MAX)
			{
				jump[i] = min(jump[i], jump[j] + 1);
				break;
			}
		}
	}
	return jump[n-1];
}

int main()
{
	int arr[] = {1, 3, 6, 1, 9,7};
	int size = sizeof(arr)/sizeof(int);
	cout<< func(arr,size);
	return 0;
}

Choices:
- O(n log n)
- O(n)
- O(n1/2)
- O(n2)


Question:
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;

void func(int arr[], int n)
{
	int count[n];
	memset(count, 0, sizeof(count));

	for (int i=n-2; i>=0; i--)
	{
		if (arr[i] >= n - i - 1)
			count[i]++;

		for (int j=i+1; j < n-1 && j <= arr[i] + i; j++)

			if (count[j] != -1)
				count[i] += count[j];

		if (count[i] == 0)
			count[i] = -1;
	}

	for (int i=0; i<n; i++)
		cout << count[i] << " ";
}

int main()
{
	int arr[] = {1, 3, 5, 8, 9};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, n);
	return 0;
}

Choices:
- 3
- 4
- 4 4 2 1 0
- 4 2 2 0 1


Question:
What will be the worst case time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;

void func(int arr[], int n)
{
	int count[n];
	memset(count, 0, sizeof(count));

	for (int i=n-2; i>=0; i--)
	{
		if (arr[i] >= n - i - 1)
			count[i]++;

		for (int j=i+1; j < n-1 && j <= arr[i] + i; j++)

			if (count[j] != -1)
				count[i] += count[j];

		if (count[i] == 0)
			count[i] = -1;
	}

	for (int i=0; i<n; i++)
		cout << count[i] << " ";
}

int main()
{
	int arr[] = {1, 3, 5, 8, 9};
	int n = sizeof(arr) / sizeof(arr[0]);
	func(arr, n);
	return 0;
}

Choices:
- O(n1/2)
- O(n)
- O(n3/2)
- O(n2)


Question:
What’s wrong with this code which returns xor of two nodes address ?
//struct is common userdefined datatype in c/c++ and class is it's alternative

struct node* XOR (struct node *a, struct node *b)
{
    //this logic is used to fill the nodes with address of a xor linked list
    return  ((int) (a) ^ (int) (b));
}

Choices:
- nothing wrong. everything is fine
- type casting at return is missing
- parameters are wrong
- total logic is wrong


Question:
What is missing in this logic of finding a path in the tree for a given sum (i.e checking whether there will be a path from roots to leaf nodes with given sum)?
checkSum(struct bin-treenode *root , int sum) :
  if(root==null)
    return sum as 0
  else :
     leftover_sum=sum-root_node-->value
     //missing

Choices:
- code for having recursive calls to either only left tree or right trees or to both subtrees depending on their existence
- code for having recursive calls to either only left tree or right trees
- code for having recursive calls to either only left tree
- code for having recursive calls to either only right trees


Question:
What must be the missing logic below so as to print mirror of a tree as below as an example?
<img src="https://www.sanfoundry.com/wp-content/uploads/2017/08/data-structure-questions-answers-binary-trees-linked-lists-q9.png" alt="data-structure-questions-answers-binary-trees-linked-lists-q9" width="394" height="158" class="aligncenter size-full wp-image-155640" srcset="https://www.sanfoundry.com/wp-content/uploads/2017/08/data-structure-questions-answers-binary-trees-linked-lists-q9.png 394w, https://www.sanfoundry.com/wp-content/uploads/2017/08/data-structure-questions-answers-binary-trees-linked-lists-q9-300x120.png 300w" sizes="(max-width: 394px) 100vw, 394px" />
if(rootnode):
  mirror(rootnode-->left)
  mirror(rootnode-->right)

  //missing

end

Choices:
- swapping of left and right nodes is missing
- swapping of left with root nodes is missing
- swapping of right with root nodes is missing
- nothing is missing


Question:
What is the code below trying to print?
void print(tree *root,tree *node)
{
  if(root ==null) return 0
  if(root-->left==node || root-->right==node) || print(root->left,node)
  ||printf(root->right,node)
  {
     print(root->data)
  }
}

Choices:
- just printing all nodes
- not a valid logic to do any task
- printing ancestors of a node passed as argument
- printing nodes from leaf node to a node passed as argument


Question:
What does the following piece of code do?
public void func(Tree root)
{
	func(root.left());
	func(root.right());
	System.out.println(root.data());
}

Choices:
- Preorder traversal
- Inorder traversal
- Postorder traversal
- Level order traversal


Question:
What does the following piece of code do?
public void func(Tree root)
{
	System.out.println(root.data());
	func(root.left());
	func(root.right());
}

Choices:
- Preorder traversal
- Inorder traversal
- Postorder traversal
- Level order traversal


Question:
Why the below pseudo code where x is a value, wt is weight factor and t is root node can’t insert?
WeightBalanceTreeNode insert(int x, int wt, WeightBalanceTreeNode k) :

           if (k == null)
                k = new WeightBalanceTreeNode(x, wt, null, null)
           else if (x < t.element) :

                k.left = insert (x, wt, k.left)
                if (k.left.weight < k.weight)
                    k = rotateWithRightChild (k)

            else if (x > t.element) :

                k.right = insert (x, wt, k.right)
                if (k.right.weight < k.weight)
                    k = rotateWithLeftChild (k)

Choices:
- when x>t. element Rotate-with-left-child should take place and vice versa
- the logic is incorrect
- the condition for rotating children is wrong
- insertion cannot be performed in weight balanced trees


Question:
What is the below pseudo code trying to do, where pt is a node pointer and root pointer?
  redblack(Node root, Node pt) :
    if (root == NULL)
       return pt

    if (pt.data < root.data)
    {
        root.left  =   redblack(root.left, pt);
        root.left.parent = root
    }
    else if (pt.data > root.data)
    {
        root.right = redblackt(root.right, pt)
        root.right.parent = root
    }
   return root

Choices:
- insert a new node
- delete a node
- search a node
- count the number of nodes


Question:
What output does the below pseudo code produces?
    Tree_node function(Tree_node x)
    {
        Tree_node y = x.left;
        x.left = y.right;
        y.right = x;
        return y;
    }

Choices:
- right rotation of subtree
- left rotation of subtree
- zig-zag operation
- zig-zig operation


Question:
What is wrong with below code for inorder traversal of inorder threaded binary tree:
   inordertraversal(threadedtreenode root):
   threadedtreenode q = inorderpredecessor(root)
   while(q!=root):
   q=inorderpredecessor(q)
   print q.data

Choices:
- inordersuccessor instead of inorderpredecessor must be done
- code is correct
- it is code for post order
- it is code for pre order


Question:
Given the code, choose the correct option that is consistent with the code. (Here A is the heap)
	build(A,i)
	left-> 2*i
	right->2*i +1
	temp- > i
	if(left<= heap_length[A] ans A[left] >A[temp])
	temp -> left
	if (right = heap_length[A] and A[right] > A[temp])
	temp->right
	if temp!= i
	swap(A[i],A[temp])
	build(A,temp)

Choices:
- It is the build function of max heap
- It is the build function of min heap
- It is general build function of any heap
- It is used to search element in any heap


Question:
State the complexity of algorithm given below.
	int function(vector<int> arr)
	int len=arr.length();
	if(len==0)
	return;
	temp=arr[len-1];
	arr.pop_back();
	return temp;

Choices:
- o(n)
- O(logn)
- O(1)
- O(n logn)


Question:
For construction of a binary heap with property that parent node has value less than child node. In reference to that which line is incorrect. Line indexed from 1.
1. add(int k)
2. {
3.     heap_size++;
4.     int i = heap_size - 1;
5.     harr[i] = k;
6.     while (i != 0 && harr[parent(i)] < harr[i])
7.     {
8.             swap(&harr[i], &harr[parent(i)]);
9.             i = parent(i);
10.    }
11. }

Choices:
- Line – 3
- Line – 5
- Line – 6
- Line – 7


Question:
What is the complexity of given function of insertion.
	insert(int n)
	{
		if(buffer_size()< maxi_biffer_size())
		buffer_aar[ind]==n;
		else
		move_to_heap(buffer,buffer+maxi_buffer_size())
	}

Choices:
- O(logn)
- amortized O(1)
- O(n)
- O (n*logn)


Question:
What does this pseudo_code return ?
	int myfun(heap_arr[])
	{
		int mini=INF;
		for(int i=0;i<tot_node;i++)
		mini=min(mini,heap_arr)
		return mini;
	}

Choices:
- Last added element to heap
- First element added to heap
- Root of the heap
- Leftmost node of the heap


Question:
What is wrong with the following code of insertion in fibonacci heap.
Choose the correct option
	FIB-INSERT(H, x)
	degree[x]= 0
	p[x]=  NIL
	child[x] =NIL
	left[x] =x
	right[x] =x
	mark[x] =FALSE
	concatenate the root list containing x with root list H
	if min[H] = NIL or key[x] > key[min[H]]
	then min[H]= x
	n[H]= n[H] + 1

Choices:
- Line -11
- Line -3
- Line 9
- Line 7


Question:
What will be the order of new heap created after union of heap H1 and H2 when created by the following code.Initially both are of the order n.
	FIB_UNION(H1,H2)
	{
		H =MAKE_HEAP()
		min[H]= min[H1]
		concatenate the root list of H2 with the root list of H
		if (min[H1] = NIL) or (min[H2]!= NIL and min[H2] < min[H1])
		then min[H] = min[H2]
		n[H]=  n[H1] + n[H2]
		free the objects H1 and H2
		return H
	}

Choices:
- n+1
- n+n/2
- nlogn
- 2*n


Question:
Following code snippet is the function to insert a string in a trie. Find the missing line.
private void insert(String str)
    {
        TrieNode node = root;
        for (int i = 0; i < length; i++)
        {
            int index = key.charAt(i) - 'a';
            if (node.children[index] == null)
                node.children[index] = new TrieNode();

            ________________________
        }

        node.isEndOfWord = true;
    }

Choices:
- node = node.children[index];
- node = node.children[str.charAt(i + 1)];
- node = node.children[index++];
- node = node.children[index++];


Question:
Input Sequence:-
9
0 1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 1
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 1 1
0 0 0 0 1 0 1 0 0
1 0 1 0 0 0 1 0 0

Choices:
- 2
- 6
- 8
- 4


Question:
For which type of graph, the given program won’t run infinitely? The Input would be in the form of an adjacency Matrix and n is its dimension (1<n<10).
#include <bits/stdc++.h>
using namespace std;
int G[10][10];
void fun(int n);

int main()
{
	int num=0;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
 		for(int j=0;j<n;j++)
        		cin>>G[i][j];
    	fun(n);
	return 0;
}

void fun(int n)
{
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	if(G[i][j]==1)
	j--;
}

Choices:
- All Fully Connected Graphs
- All Empty Graphs
- All Bipartite Graphs
- All simple graphs


Question:
Given the following adjacency matrix of a graph(G) determine the number of 	components in the G.
[0 1 1 0 0 0],
[1 0 1 0 0 0],
[1 1 0 0 0 0],
[0 0 0 0 1 0],
[0 0 0 1 0 0],
[0 0 0 0 0 0].

Choices:
- 1
- 2
- 3
- 4


Question:
Complete the given snippet of code for the adjacency list representation of a weighted directed graph.
	class neighbor
        {
		int vertex, weight;
		____ next;
	}

	class vertex
        {
		string name;
		_____ adjlist;
	}

	vertex adjlists[101];

Choices:
- vertex, vertex
- neighbor, vertex
- neighbor, neighbor
- vertex, neighbor


Question:
What would be the time complexity of the following function which adds an edge between two vertices i and j, with some weight ‘weigh’ to the graph having V vertices?
vector<int> adjacent[15] ;
vector<int> weight[15];

void addEdge(int i,int j,int weigh)
{
	adjacent[a].push_back(i);
	adjacent[b].push_back(j);
	weight[a].push_back(weigh);
	weight[b].push_back(weigh);
}

Choices:
- O(1)
- O(V)
- O(V*V)
- O(log V)


Question:
What would be the output of the following C++ program if the given input is
0 0 0 1 1
0 0 0 0 1
0 0 0 1 0
1 0 1 0 0
1 1 0 0 0

#include <bits/stdc++.h>
using namespace std;
bool visited[5];
int G[5][5];

void fun(int i)
{
	cout<<i<<" ";
	visited[i]=true;
	for(int j=0;j<5;j++)
		if(!visited[j]&&G[i][j]==1)
			fun(j);
}

int main()
{
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			cin>>G[i][j];

	for(int i=0;i<5;i++)
		visited[i]=0;

	fun(0);
		return 0;
}

Choices:
- 0 2 3 1 4
- 0 3 2 4 1
- 0  2 3 4 1
- 0 3 2 1 4


Question:
What does the following piece of code do?
for (int i = 0; i < arr.length-1; i++)
{
    for (int j = i+1; j < arr.length; j++)
    {
        if( (arr[i].equals(arr[j])) && (i != j) )
        {
            System.out.println(arr[i]);
        }
    }
}

Choices:
- Print the duplicate elements in the array
- Print the element with maximum frequency
- Print the unique elements in the array
- Prints the element with minimum frequnecy


Question:
What will be the output of the following code?
#include<bits/stdc++.h>
using namespace std;

void func(char* str2, char* str1)
{
	int m = strlen(str2);
	int n = strlen(str1);
	for (int i = 0; i <= n - m; i++)
        {
		int j;

		for (j = 0; j < m; j++)
			if (str1[i + j] != str2[j])
				break;

		if (j == m)
			cout << i << endl;
	}
}

int main()
{
	char str1[] = "1253234";
	char str2[] = "323";
	func(str2, str1);
	return 0;
}

Choices:
- 1
- 2
- 3
- 4


Question:
What will be the worst case time complexity of the following code?
#include<bits/stdc++.h>
using namespace std;

void func(char* str2, char* str1)
{
	int m = strlen(str2);
	int n = strlen(str1);
	for (int i = 0; i <= n - m; i++)
        {
		int j;

		for (j = 0; j < m; j++)
			if (str1[i + j] != str2[j])
				break;

		if (j == m)
			cout << i << endl;
	}
}

int main()
{
	char str1[] = "1253234";
	char str2[] = "323";
	func(str2, str1);
	return 0;
}

Choices:
- O(n)
- O(m)
- O(m * n)
- O(m + n)


Question:
What will be the auxiliary space complexity of the following code?
#include<bits/stdc++.h>
using namespace std;

void func(char* str2, char* str1)
{
	int m = strlen(str2);
	int n = strlen(str1);
	for (int i = 0; i <= n - m; i++)
        {
		int j;

		for (j = 0; j < m; j++)
			if (str1[i + j] != str2[j])
				break;

		if (j == m)
			cout << i << endl;
	}
}

int main()
{
	char str1[] = "1253234";
	char str2[] = "323";
	func(str2, str1);
	return 0;
}

Choices:
- O(n)
- O(1)
- O(log n)
- O(m)


Question:
What will be the best case time complexity of the following code?
#include<bits/stdc++.h>
using namespace std;
void func(char* str2, char* str1)
{
	int m = strlen(str2);
	int n = strlen(str1);

	for (int i = 0; i <= n - m; i++)
        {
		int j;

		for (j = 0; j < m; j++)
			if (str1[i + j] != str2[j])
				break;

		if (j == m)
			cout << i << endl;
	}
}

int main()
{
	char str1[] = "1253234";
	char str2[] = "323";
	func(str2, str1);
	return 0;
}

Choices:
- O(n)
- O(m)
- O(m * n)
- O(m + n)


Question:
What is the average time complexity of in place merge sort when we use the following function for merging?
void in_place_merge(int arr[], int l, int middle, int r)
{
	int start2 = middle + 1;
	if (arr[middle] <= arr[start2])
        {
		return;
	}
	while (l <= middle && start2 <= r)
        {
		if (arr[l] <= arr[start2])
                {
			l++;
		}
		else
                {
			int val = arr[start2];
			int index = start2;
			while (index != l)
                        {
				arr[index] = arr[index - 1];
				index--;
			}
			arr[l] = val;
		        l++;
			middle++;
			start2++;
		}
	}
}

Choices:
- O(n log n)
- O(n2)
- O(n2 log n)
- O(n log n2)


Question:
Choose the correct option to fill? X so that the code given below implements the Heap sort.
#include <stdio.h>
void heapify(int arr[], int n, int i)
{
    int largest = i; // Initialize largest as root
    int l = 2*i + 1; // left = 2*i + 1
    int r = 2*i + 2; // right = 2*i + 2
    if (l < n && arr[l] > arr[largest])
        largest = l;
    if (r < n && arr[r] > arr[largest])
        largest = r;
    if (largest != i)
    {
        swap(arr[i], arr[largest]);
        heapify(arr, n, largest);
    }
}
void heapSort(int arr[], int n)
{
    for (int i = n / 2 - 1; i >= 0; i--)
        heapify(arr, n, i);
    for (int i=n-1; i>=0; i--)
    {
        X;
        heapify(arr, i, 0);
    }
}
void printArray(int arr[], int n)
{
    for (int i=0; i<n; ++i)
        printf(“%d”,arr[i]);
    printf(“\n”);
}
int main()
{
    int arr[] = {12, 11, 13, 5, 6, 7};
    int n = sizeof(arr)/sizeof(arr[0]);
    heapSort(arr, n);
    printf(“Sorted array is \n");
    printArray(arr, n);
}

Choices:
- swap(arr[0], arr[n])
- swap(arr[i], arr[n])
- swap(arr[0], arr[i])
- swap(arr[i], arr[2*i])


Question:
What will be the output of the given C++ code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[] = {1,3,4,2,5};
    int n = sizeof(arr)/sizeof(arr[0]);
    sort(arr, arr+n, greater<int>());
    int a;
    for (a = 0; a < n; a++)
        cout << arr[a] << " ";
    return 0;
}

Choices:
- 1 2 3 4 5
- 1 3 4 2 5
- 5 4 3 2 1
- error


Question:
What will be the output of the given C++ code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[] = {1, 3,4,2,5};
    int n = sizeof(arr)/sizeof(arr[0]);
    sort(arr, arr+n);
    int a;
    for ( a = 0; a< n; a++)
        cout << arr[a] << " ";
    return 0;
}

Choices:
- 1 2 3 4 5
- 1 3 4 2 5
- 5 4 3 2 1
- error


Question:
What will be the output of the given C++ code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int arr[] = {1, 3,4,2,5};
	int n = sizeof(arr)/sizeof(arr[0]);
	sort(arr+2, arr+n, greater<int>());
        int a;
	for (int a = 0; a < n; a++)
		cout << arr[a] << " ";
	return 0;
}

Choices:
- 1 2 3 4 5
- 1 5 4 3 2
- 5 4 3 2 1
- 1 3 5 4 2


Question:
What will be the output of the given Java code?
import java.util.Arrays;
public class SortExample
{
	public static void main(String[] args)
	{
		// Our arr contains 8 elements
		int[] arr = {10,7,9,5,8,4};
		Arrays.sort(arr);
		System.out.printf(Arrays.toString(arr));
	}
}

Choices:
- [4,5,7,8,9,10]
- [10,9,8,7,5,4]
- 4,5,7,8,9,10
- error


Question:
What will be the output of the given Java code?
import java.util.Arrays;
public class SortExample
{
	public static void main(String[] args)
	{
		int[] arr = {10,7,9,5,8,4};
		Arrays.sort(arr, 1, 3);
		System.out.printf(Arrays.toString(arr));
	}
}

Choices:
- [4,5,7,8,9,10]
- [10,9,8,7,5,4]
- [10,5,7,8,9,4]
- [10,7,9,5,8,4]


Question:
The insert() procedure, given below, builds the BST on the input elements, which is the first step of the binary tree sort. Choose the correct to fill the condition.
void insert(Tree* node, int newElement)
{
	if(node== NULL)
	{
		node = createNewNode();
		node-> value = newElement;
		node -> left = NULL;
		node -> right = NULL;
		return;
	}
	else if(__________________)
	{
		insert(node->left, newElement);
	}
	else
	{
		insert(node->right, newElement);
	}
}

Choices:
- newElement > node->value
- newElement < node->value
- newElement == root->value
- newElement != root->value


Question:
The following function represents which sorting?
void Sorting(int a[], int n)
{
	bool swap = true;
	int first = 0;
	int last = n - 1;

	while (swap)
        {

		swap = false;

		for (int i = first; i < last;i++)
                {
			if (a[i] > a[i + 1])
                        {
				swap(a[i], a[i + 1]);
				swap = true;
			}
		}

		if (!swap)
			break;

		swap = false;

		--last;

		for (int i = last - 1; i >= first; i--)
                {
			if (a[i] > a[i + 1])
                        {
				swap(a[i], a[i + 1]);
				swap = true;
			}
		}

		++first;
	}
}

Choices:
- Bubble sort
- Selection sort
- Bidirectional bubble sort
- Odd-even sort


Question:
There is one small error in the following flip routine. Find out which line it is on.
	1	void flip(int arr[], int i)
	2	{
	3	      int t, init = 0;
	4	      while (init < i)
	5	      {
	6		    t = arr[init];
	7		    arr[i] = arr[init] ;
	8		    arr[i] = t;
	9		    init++;
	10		    i--;
	11	      }
	12	}

Choices:
- Line 3
- Line 5
- Line 7
- Line 9


Question:
There is a one line error in the following routine. Find that line.
		1.	int Max(int a[], int n)
		2.	{
		3.		  int mi, i;
		4.		  for (mi = 0, i = 0; i < n; i++)
		5.		  if (a[i] > a[mi])
		6.		  mi = i;
		7.		  return mi;
		8.	}

Choices:
- Line 2
- Line 4
- Line 6
- Line 5


Question:
Given a pattern of length-5 window, find the suitable modulo value.
 for s=0 to n-m
		do if p!=ts
			then if P[1..m]=T[s+1..s+m]
				then print “Pattern occurs with shift” s

Choices:
- 13
- 14
- 12
- 11


Question:
Given a pattern of length- 5 window, find the valid match in the given text.
					4 3 2 5 0

Choices:
- 11-16
- 3-8
- 13-18
- 15-20


Question:
Given a pattern of length- 5 window, find the spurious hit in the given text string.
Pattern: 2 1 9 3 6
Modulus: 21
Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Text:   9 2 7 2 1 8 3 0 5 7 1   2   1   2   1   9   3   6   2   3   9  7

Choices:
- 6-10
- 12-16
- 3-7
- 13-17


Question:
Predict the output of the following code.
#include <stdlib.h>
int main()
{
     srand(0);
     printf("%d\n", rand());
     return 0;
}

Choices:
- compilation error
- random number between 0 to RAND_MAX
- cannot be predicted
- 0


Question:
Predict the output of the following code.
#include <stdlib.h>
int main()
{
     srand(0);
     printf("%d\n", rand()%50);
     return 0;
}

Choices:
- compilation error
- random number between 0 to 50 (both inclusive)
- random number between 0 to 51 (both inclusive)
- random number between 0 to 49 (both inclusive)


Question:
What is the name given to the algorithm depicted in the pseudo code below?
procedure generate(n : integer, Arr : array):
    if n = 1 then
          output(Arr)
    else
        for i = 0; i <= n - 2; i ++ do
            generate(n - 1, Arr)
            if n is even then
                swap(Arr[i], Arr[n-1])
            else
                swap(Arr[0], Arr[n-1])
            end if
        end for
        generate(n - 1, Arr )
    end if

Choices:
- bubble sort
- heap sort
- heap’s algorithm
- prim’s algorithm


Question:
What will be the output for following code?
#include <stdio.h>
#include <string.h>
#include<iostream>
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;
}

Choices:
- AB,BA,
- BA,AB,
- AB,BA
- BA,AB,


Question:
What will be the time complexity of the given code?
#include <stdio.h>
#include <string.h>
#include<iostream>
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;
}

Choices:
- O(n2)
- O(n * n!)
- O(n!)
- O(n log n)


Question:
What will be the output of the following code?
#include <iostream>
#include<string>
using namespace std;
void func1(string input,string output)
{
    if(input.length()==0)
    {
        cout<<output<<",";
        return;
    }
    for(int i=0;i<=output.length();i++)
    func1(input.substr(1),output.substr(0,i) + input[0] + output.substr(i));
}

int main()
{
    char str[] = "AB";

	func1(str, "");
    return 0;
}

Choices:
- AA,BA,
- AB,BA,
- BA,AB,
- AB,AB,


Question:
What will be the output of the following code?
#include <stdio.h>
#include <string.h>
#include<iostream>
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[] = "AA";
	int n = strlen(str);
	func(str, 0, n-1);
	return 0;
}

Choices:
- AA,
- AA,AA
- A,A
- AA,AA,


Question:
What will be the output for the following code?
#include<stdio.h>
void combination(int arr[],int n,int r,int index,int aux[],int i);
void print(int arr[], int n, int r)
{
	int aux[r];
	combination(arr, n, r, 0, aux, 0);
}
void combination(int arr[], int n, int r, int index, int aux[], int i)
{
	if (index == r)
	{
		for (int j=0; j<r; j++)
			printf("%d ",aux[j]);
		printf(", ");
		return;
	}
	if (i >= n)
		return;
	aux[index] = arr[i];
	combination(arr, n, r, index+1, aux, i+1);
	combination(arr, n, r, index, aux, i+1);
}
int main()
{
	int arr[] = {1, 2,2};
	int r = 2;
	int n = sizeof(arr)/sizeof(arr[0]);
	print(arr, n, r);
	return 0;
}

Choices:
- 1 2, 1 2, 2 2
- 1 2, 1 2, 2 2 ,
- 1 2, 2 1, 2 2 ,
- 1 2, 2 1, 2 2


Question:
What will be the output for the following code?
#include <stdio.h>
void combination(int arr[], int aux[], int start, int end, int index, int r);
void print(int arr[], int n, int r)
{
	int aux[r];
        combination(arr, aux, 0, n-1, 0, r);
}
void combination(int arr[], int aux[], int start, int end, int index, int r)
{
	if (index == r)
	{
		for (int j=0; j<r; j++)
			printf("%d ", aux[j]);
		printf(", ");
		return;
	}
	for (int i=start; i<=end && end-i+1 >= r-index; i++)
	{   aux[index] = arr[i];
		combination(arr, aux, i+1, end, index+1, r);
	}
}
int main()
{
	int arr[] = {1, 2, 3};
	int r = 2;
	int n = sizeof(arr)/sizeof(arr[0]);
	print(arr, n, r);
}

Choices:
- 1 2, 1 3, 2 3
- 1 3,1 2,2 3,
- 1 2, 1 3, 2 3,
- 1 2,1 3,2 3,


Question:
What will be the output for the following code?
#include <stdio.h>
#include <stdlib.h>
void combination(int arr[], int aux[], int start, int end, int index, int r);
int compare (const void * a, const void * b)
{  return ( *(int*)a - *(int*)b );  }
void print(int arr[], int n, int r)
{
    int aux[r];
    qsort (arr, n, sizeof(int), compare);
    combination(arr, aux, 0, n-1, 0, r);
}
void combination(int arr[], int aux[], int start, int end, int index, int r)
{
    if (index == r)
    {
        for (int i=0; i<r; i++)
            printf("%d " ,aux[i]);
        printf(", ");
        return;
    }
    for (int i=start; i<=end && end-i+1 >= r-index; i++)
    {
        aux[index] = arr[i];
        combination(arr, aux, i+1, end, index+1, r);
        while (arr[i] == arr[i+1])
             i++;
    }
}
int main()
{
    int arr[] = {1, 2, 2};
    int r = 2;
    int n = sizeof(arr)/sizeof(arr[0]);
    print(arr, n, r);
}

Choices:
- 1 2, 1 2,2 2,
- 1 2, 2 1, 2 2,
- 1 2, 2 2,
- 1 2, 2 2, 2 1,


Question:
What is the approach implemented in the following code?
#include<iostream>
using namespace std;
void printArray(int p[], int n)
{
	for (int i = 0; i <= n-1; i++)
	cout << p[i] << " ";
	cout << endl;
}
void func1(int n)
{
	int p[n];
	int k = 0;
	p[k] = n;
	while (true)
	{
		printArray(p, k+1);
		int rem_val = 0;
		while (k >= 0 && p[k] == 1)
		{
			rem_val += p[k];
			k--;
		}
		if (k < 0) return;
		p[k]--;
		rem_val++;
		while (rem_val > p[k])
		{
			p[k+1] = p[k];
			rem_val = rem_val - p[k];
			k++;
		}
		p[k+1] = rem_val;
		k++;
	}
}

int main()
{
      int n;
      cin>>n;
      func1(n);
      return 0;
}

Choices:
- greedy approach
- dynamic programming
- recursion(divide and conquer)
- backtracking


Question:
Choose the correct statement for the following code segment?
bool check (int N)
{
    if( N & (1 << i) )
        return true;
    else
        return false;
}

Choices:
- function returns true if N is odd
- function returns true if N is even
- function returns true if ith bit of N is set
- function returns false if ith bit of N is set


Question:
What will be the output for the following code?
#include <stdio.h>
#include <math.h>
void PowerSet(char *set, int set_size)
{
	unsigned int pow_size = pow(2, set_size);
	int count, j;
	for(count = 0; count < pow_size; count++)
	{
	     for(j = 0; j < set_size; j++)
	     {

		if(count & (1<<j))
			printf("%c", set[j]);
	     }
	     printf(",");
	}
}
int main()
{
	char strset[] = {'a','b','c'};
	PowerSet(strset, 3);
	return 0;
}

Choices:
- a,b,ab,c,ac,bc,abc,
- a,b,ab,c,ac,bc,abc
- ,a,b,ab,c,ac,bc,abc,
- ,abc,bc,ac,c,ab,b,a,


Question:
What will be the time complexity of the following code?
#include <stdio.h>
#include <math.h>
void PowerSet(char *set, int set_size)
{
	unsigned int pow_size = pow(2, set_size);
	int count, j;
	for(count = 0; count < pow_size; count++)
	{
	     for(j = 0; j < set_size; j++)
	     {

		if(count & (1<<j))
			printf("%c", set[j]);
	     }
	     printf(",");
	}
}
int main()
{
	char strset[] = {'a','b','c'};
	PowerSet(strset, 3);
	return 0;
}

Choices:
- O(n 2n)
- O(n2)
- O(n log n)
- O(2n) (n is the size of set)


Question:
What will be the auxiliary space requirement of the following code?
#include <stdio.h>
#include <math.h>
void PowerSet(char *set, int set_size)
{
	unsigned int pow_size = pow(2, set_size);
	int count, j;
	for(count = 0; count < pow_size; count++)
	{
	for(j = 0; j < set_size; j++)
	{
		if(count & (1<<j))
			printf("%c", set[j]);
	}
	printf(",");
	}
}
int main()
{
	char strset[] = {'a','b','c'};
	PowerSet(strset, 3);
	return 0;
}

Choices:
- O(n)
- O(1)
- O(n log n)
- O(2n) (n is the size of set)


Question:
Find the output of the following code.
#include<math.h>
#include<iostream>
using namespace std;
void distance(float x, float y, float a, float b, float c)
{
	float d = fabs((a * x + b * y + c)) / (sqrt(a * a + b * b));
	cout<<d;
	return;
}
int main()
{
	float x = -2;
	float y = -3;
	float a = 5;
	float b = -2;
	float c = - 4;
	distance(x, y, a, b, c);
	return 0;
}

Choices:
- 2.8
- 1.8
- 1.4
- 2.4


Question:
Find the output of the following code.
#include <bits/stdc++.h>
using namespace std;
void crossP(int A[], int B[], int cross[])
{
	cross[0] = A[1] * B[2] - A[2] * B[1];
	cross[1] = A[0] * B[2] - A[2] * B[0];
	cross[2] = A[0] * B[1] - A[1] * B[0];
}
int main()
{
	int A[] = { 1, 2, 4 };
	int B[] = { 2, 3, 2 };
	int cross[3];
	crossP(A, B, cross);
	for (int i = 0; i < 3; i++)
		cout << cross[i] << " ";
	return 0;
}

Choices:
- 1 2 5
- -1 -5 -3
- -6 -8 -1
- -8 -6 -1


Question:
Complete the program.
n=rows[W]
D(0)=W
for k=1 to n
     do for i=1 to n
          do for j=1 to n
                 do ________________________________
return D(n)

Choices:
- dij(k)=min(dij(k-1), dik(k-1) – dkj(k-1))
- dij(k)=max(dij(k-1), dik(k-1) – dkj(k-1))
- dij(k)=min(dij(k-1), dik(k-1) + dkj(k-1))
- dij(k)=max(dij(k-1), dik(k-1) + dkj(k-1))


Question:
What will happen when the below code snippet is executed?
void my_recursive_function()
{
   my_recursive_function();
}
int main()
{
   my_recursive_function();
   return 0;
}

Choices:
- 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


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

Choices:
- 10
- 1
- 10 9 8 …   1 0
- 10 9 8 …   1


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

Choices:
- return
- printf(“%d “, n)
- if(n == 0)
- my_recursive_function(n-1)


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

Choices:
- 9
- 10
- 11
- 12


Question:
What does the following recursive code do?
void my_recursive_function(int n)
{
     if(n == 0)
     return;
     my_recursive_function(n-1);
     printf("%d ",n);
}
int main()
{
     my_recursive_function(10);
     return 0;
}

Choices:
- Prints the numbers from 10 to 1
- Prints the numbers from 10 to 0
- Prints the numbers from 1 to 10
- Prints the numbers from 0 to 10


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

Choices:
- 123456789
- 10
- 0
- 9


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

Choices:
- 6
- 9
- 5
- 10


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

Choices:
- 3
- 4
- 5
- 6


Question:
Consider the following iterative implementation to find the factorial of a number. Which of the lines should be inserted to complete the below code?
int main()
{
    int n = 6, i;
    int fact = 1;
    for(i=1;i<=n;i++)
      _________;
    printf("%d",fact);
    return 0;
}

Choices:
- fact = fact + i
- fact = fact * i
- i = i * fact
- i = i + fact


Question:
Consider the following recursive implementation to find the factorial of a number. Which of the lines should be inserted to complete the below code?
int fact(int n)
{
     if(_________)
        return 1;
     return n * fact(n - 1);
}
int main()
{
      int n = 5;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Choices:
- n = 0
- n != 0
- n == 0
- n == 1


Question:
The time complexity of the following recursive implementation to find the factorial of a number is ________
int fact(int n)
{
     if(_________)
        return 1;
     return n * fact(n - 1);
}
int main()
{
      int n = 5;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the space complexity of the following recursive implementation to find the factorial of a number?
int fact(int n)
{
     if(_________)
        return 1;
     return n * fact(n - 1);
}
int main()
{
      int n = 5;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


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

Choices:
- return 1
- return n * fact(n-1)
- if(n == 0)
- if(n == 1)


Question:
What is the output of the following code?
int fact(int n)
{
      if(n == 0)
        return 1;
      return n * fact(n - 1);
}
int main()
{
      int n = 0;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Choices:
- 0
- 1
- 2
- 3


Question:
What is the output of the following code?
int fact(int n)
{
      if(n == 0)
        return 1;
      return n * fact(n - 1);
}
int main()
{
      int n = 1;
      int ans = fact(n);
      printf("%d",ans);
      return 0;
}

Choices:
- 0
- 1
- 2
- 3


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

Choices:
- 4
- 5
- 6
- 7


Question:
What is the output of the following code?
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;
}

Choices:
- 24
- 120
- 720
- 1


Question:
What is the time 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;
}

Choices:
- O(1)
- O(2*n)
- O(n2)
- O(2n)


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

Choices:
- O(1)
- O(2*n)
- O(n2)
- O(2n)


Question:
What is the output of the following code?
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 = -1;
     int ans = fibo(n);
     printf("%d",ans);
     return 0;
}

Choices:
- 0
- 1
- Compile time error
- Runtime error


Question:
What is the output of the following code?
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;
}

Choices:
- 1
- 2
- 3
- 5


Question:
How many times will the function fibo() be called when the following code is executed?
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;
}

Choices:
- 5
- 6
- 8
- 9


Question:
What is the output of the following code?
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 = 10;
     int ans = fibo(n);
     printf("%d",ans);
     return 0;
}

Choices:
- 21
- 34
- 55
- 13


Question:
What is the output of the following code?
#include<stdio.h>
int get_sum(int n)
{
      int sm, i;
      for(i = 1; i <= n; i++)
        sm += i;
      return sm;
}
int main()
{
    int n = 10;
    int ans = get_sum(n);
    printf("%d",ans);
    return 0;
}

Choices:
- 55
- 45
- 35
- Depends on compiler


Question:
What is the time complexity of the following iterative method used to find the sum of the first n natural numbers?
#include<stdio.h>
int get_sum(int n)
{
      int sm, i;
      for(i = 1; i <= n; i++)
        sm += i;
      return sm;
}
int main()
{
    int n = 10;
    int ans = get_sum(n);
    printf("%d",ans);
    return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the time complexity of the following recursive implementation used to find the sum of the first n natural numbers?
#include<stdio.h>
int recursive_sum(int n)
{
      if(n == 0)
        return 0;
      return n + recursive_sum(n - 1);
}
int main()
{
     int n = 5;
     int ans = recursive_sum(n);
     printf("%d",ans);
     return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_sum(int n)
{
      if(n == 0)
        return 0;
      return n + recursive_sum(n - 1);
}
int main()
{
      int n = 5;
      int ans = recursive_sum(n);
      printf("%d",ans);
      return 0;
}

Choices:
- 10
- 15
- 21
- 14


Question:
How many times is the function recursive_sum() called when the following code is executed?
#include<stdio.h>
int recursive_sum(int n)
{
      if(n == 0)
        return 0;
      return n + recursive_sum(n - 1);
}
int main()
{
     int n = 5;
     int ans = recursive_sum(n);
     printf("%d",ans);
     return 0;
}

Choices:
- 4
- 5
- 6
- 7


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_sum(int n)
{
      if(n == 0)
        return 0;
      return n + recursive_sum(n - 1);
}
int main()
{
     int n = 0;
     int ans = recursive_sum(n);
     printf("%d",ans);
     return 0;
}

Choices:
- -1
- 0
- 1
- runtime error


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_sum(int n)
{
      if(n == 0)
        return 0;
      return n + recursive_sum(n - 1);
}
int main()
{
     int n = -4;
     int ans = recursive_sum(n);
     printf("%d",ans);
     return 0;
}

Choices:
- 0
- -10
- 1
- runtime error


Question:
What is the output of the following code?
#include<stdio.h>
int sum_of_digits(int n)
{
      int sm = 0;
      while(n != 0)
      {
          sm += n%10;
          n /= 10;
      }
      return sm;
}
int main()
{
      int n = 1234;
      int ans = sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Choices:
- 1
- 3
- 7
- 10


Question:
What is the time complexity of the following recursive implementation to find the sum of digits of a number n?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return _________;
}
int main()
{
      int n = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Choices:
- O(n)
- O(1)
- O(len(n)), where len(n) is the number of digits in n
- O(1/2)


Question:
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 = 1234321;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Choices:
- 10
- 16
- 15
- 14


Question:
How many times is the function recursive_sum_of_digits() called when the following code is executed?
#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 = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Choices:
- 6
- 7
- 5
- 9


Question:
You have to find the sum of digits of a number given that the number is always greater than 0. Which of the following base cases can replace the base case for the below 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 = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Choices:
- if(n == 0) return 1
- if(n == 1) return 0
- if(n == 1) return 1
- no need to modify the base case


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

Choices:
- 0
- 1
- runtime error
- -1


Question:
What is the output of the following code?
#include<stdio.h>
int cnt =0;
int my_function(int n, int sm)
{
      int i, tmp_sm;
      for(i=1;i<=n;i++)
      {
          tmp_sm = recursive_sum_of_digits(i);
          if(tmp_sm == sm)
            cnt++;
      }
      return cnt;
}
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 = 20, sum = 3;
      int ans = my_function(n,sum);
      printf("%d",ans);
      return 0;
}

Choices:
- 0
- 1
- 2
- 3


Question:
What is the output of the following code?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(i < j)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
int main()
{
      char s[100] = "reverse";
      reverse_string(s);
      printf("%s",s);
      return 0;
}

Choices:
- ersevre
- esrever
- eserver
- eresevr


Question:
What does the following code do?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(i < j)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
int main()
{
      char s[100] = "abcdefg";
      char t[100];
      strcpy(t,s);
      reverse_string(s);
      if(strcmp(t,s) == 0)
        printf("Yes");
      else
        printf("No");
      return 0;
}

Choices:
- Copies a string to another string
- Compares two strings
- Reverses a string
- Checks if a string is a palindrome


Question:
What is the output of the following code?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(i < j)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
int main()
{
      char s[100] = "rotator";
      char t[100];
      strcpy(t,s);
      reverse_string(s);
      if(strcmp(t,s) == 0)
        printf("Yes");
      else
        printf("No");
      return 0;
}

Choices:
- Yes
- No
- Runtime error
- Compile time error


Question:
What is the output of the following code?
#include<stdio.h>
#include<string.h>
void recursive_reverse_string(char *s, int left, int right)
{
     if(left < right)
     {
         char tmp = s[left];
         s[left] = s[right];
         s[right] = tmp;
         recursive_reverse_string(s, left+1, right-1);
     }
}
int main()
{
     char s[100] = "recursion";
     int len = strlen(s);
     recursive_reverse_string(s,0,len-1);
     printf("%s",s);
     return 0;
}

Choices:
- recursion
- nsoirucer
- noisrcuer
- noisrucer


Question:
How many times is the function recursive_reverse_string() called when the following code is executed?
#include<stdio.h>
#include<string.h>
void recursive_reverse_string(char *s, int left, int right)
{
     if(left < right)
     {
         char tmp = s[left];
         s[left] = s[right];
         s[right] = tmp;
         recursive_reverse_string(s, left+1, right-1);
     }
}
int main()
{
     char s[100] = "madam";
     int len = strlen(s);
     recursive_reverse_string(s,0,len-1);
     printf("%s",s);
     return 0;
}

Choices:
- 3
- 4
- 5
- 6


Question:
What is the output of the following code?
#include<stdio.h>
void dec_to_bin(int n)
{
    int arr[31],len = 0,i;
    if(n == 0)
    {
        arr[0] = 0;
        len = 1;
    }
    while(n != 0)
    {
        arr[len++] = n % 2;
        n /= 2;
    }
    for(i=len-1; i>=0; i--)
        printf("%d",arr[i]);
}
int main()
{
    int n = 63;
    dec_to_bin(n);
    return 0;
}

Choices:
- 111111
- 111011
- 101101
- 101010


Question:
What is the output of the following code?
#include<stdio.h>
void dec_to_bin(int n)
{
      int arr[31],len = 0,i;
      if(n == 0)
      {
          arr[0] = 0;
          len = 1;
      }
      while(n != 0)
      {
          arr[len++] = n % 2;
          n /= 2;
      }
      for(i=len-1; i>=0; i--)
        printf("%d",arr[i]);
}
int main()
{
     int n = 0;
     dec_to_bin(n);
     return 0;
}

Choices:
- 0
- 1
- Runtime error
- Garbage value


Question:
What is the time complexity of the following code used to convert a decimal number to its binary equivalent?
#include<stdio.h>
void dec_to_bin(int n)
{
      int arr[31],len = 0,i;
      if(n == 0)
      {
          arr[0] = 0;
          len = 1;
      }
      while(n != 0)
      {
          arr[len++] = n % 2;
          n /= 2;
      }
      for(i=len-1; i>=0; i--)
        printf("%d",arr[i]);
}
int main()
{
     int n = 0;
     dec_to_bin(n);
     return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(logn)


Question:
What is the output of the following code?
#include<stdio.h>
int arr[31], len = 0;
void recursive_dec_to_bin(int n)
{
      if(n == 0 && len == 0)
      {
          arr[len++] = 0;
          return;
      }
      if(n == 0)
         return;
      arr[len++] = n % 2;
      recursive_dec_to_bin(n/2);
}
int main()
{
     int n = -100,i;
     recursive_dec_to_bin(n);
     for(i=len-1; i>=0; i--)
     printf("%d",arr[i]);
     return 0;
}

Choices:
- -1100100
- 1100100
- 2’s complement of 1100100
- Garbage value


Question:
What is the time complexity of the recursive implementation used to convert a decimal number to its binary equivalent?
#include<stdio.h>
int arr[31], len = 0;
void recursive_dec_to_bin(int n)
{
      if(n == 0 && len == 0)
      {
          arr[len++] = 0;
          return;
      }
      if(n == 0)
         return;
      arr[len++] = n % 2;
      recursive_dec_to_bin(n/2);
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(logn)


Question:
What is the space complexity of the recursive implementation used to convert a decimal number to its binary equivalent?
#include<stdio.h>
int arr[31], len = 0;
void recursive_dec_to_bin(int n)
{
      if(n == 0 && len == 0)
      {
          arr[len++] = 0;
          return;
      }
      if(n == 0)
         return;
      arr[len++] = n % 2;
      recursive_dec_to_bin(n/2);
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(logn)


Question:
What is the output of the following code?
#include<stdio.h>
int arr[31], len = 0;
void recursive_dec_to_bin(int n)
{
      if(n == 0 && len == 0)
      {
          arr[len++] = 0;
          return;
      }
      if(n == 0)
         return;
      arr[len++] = n % 2;
      recursive_dec_to_bin(n/2);
}
int main()
{
     int n = 111,i;
     recursive_dec_to_bin(n);
     for(i=len-1; i>=0; i--)
     printf("%d",arr[i]);
     return 0;
}

Choices:
- 1110111
- 1001111
- 1101111
- 1010111


Question:
How many times is the function recursive_dec_to_bin() called when the following code is executed?
#include<stdio.h>
int arr[31], len = 0;
void recursive_dec_to_bin(int n)
{
      if(n == 0 && len == 0)
      {
          arr[len++] = 0;
          return;
      }
      if(n == 0)
         return;
      arr[len++] = n % 2;
      recursive_dec_to_bin(n/2);
}
int main()
{
    int n = 111,i;
    recursive_dec_to_bin(n);
    for(i=len-1; i>=0; i--)
    printf("%d",arr[i]);
    return 0;
}

Choices:
- 7
- 8
- 9
- 10


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

Choices:
- 4
- 5
- 6
- 7


Question:
What is the time complexity of the following iterative 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 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;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(logn)


Question:
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;
      int len = get_len();
      printf("%d",len);
      return 0;
}

Choices:
- 0
- Garbage value
- Compile time error
- Runtime error


Question:
Which of the following can be the base case for the recursive implementation used to find the length of linked list?
#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;
      int len = get_len();
      printf("%d",len);
      return 0;
}

Choices:
- if(current_node == 0) return 1
- if(current_node->next == 0) return 1
- if(current_node->next == 0) return 0
- if(current_node == 0) return 0


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

Choices:
- recursive_get_len(current_node)
- 1 + recursive_get_len(current_node)
- recursive_get_len(current_node->next)
- 1 + recursive_get_len(current_node->next)


Question:
What is the output of the following code?
#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 1 + recursive_get_len(current_node->next);
}
int main()
{
      int arr[10] = {-1,2,3,-3,4,5,0}, n = 7, 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;
}

Choices:
- 6
- 7
- 8
- 9


Question:
What is the time complexity of the following code 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 1 + recursive_get_len(current_node->next);
}
int main()
{
      int arr[10] = {-1,2,3,-3,4,5,0}, n = 7, 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;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the output of the following code?
#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 1 + recursive_get_len(current_node->next);
}
int main()
{
      int arr[10] = {-1,2,3,-3,4,5}, n = 6, 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;
}

Choices:
- 5
- 6
- 7
- 8


Question:
How many times is the function recursive_get_len() called when the following code is executed?
#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 1 + recursive_get_len(current_node->next);
}
int main()
{
      int arr[10] = {-1,2,3,-3,4,5}, n = 6, 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;
}

Choices:
- 5
- 6
- 7
- 8


Question:
What is the output of the following code?
#include<stdio.h>
int get_len(char *s)
{
      int len = 0;
      while(s[len] != '\0')
        len++;
      return len;
}
int main()
{
      char *s = "lengthofstring";
      int len = get_len(s);
      printf("%d",len);
      return 0;
}

Choices:
- 14
- 0
- Compile time error
- Runtime error


Question:
What is the time complexity of the following code used 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 = "lengthofstring";
      int len = get_len(s);
      printf("%d",len);
      return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(logn)


Question:
What is the output of the following code?
#include<stdio.h>
int get_len(char *s)
{
      int len = 0;
      while(s[len] != '\0')
        len++;
      return len;
}
int main()
{
      char *s = "";
      int len = get_len(s);
      printf("%d",len);
      return 0;
}

Choices:
- 0
- 1
- Runtime error
- Garbage value


Question:
Which of the following can be the base case for the recursive implementation used to find the length of a string?
#include<stdio.h>
int get_len(char *s)
{
      int len = 0;
      while(s[len] != '\0')
        len++;
      return len;
}
int main()
{
      char *s = "";
      int len = get_len(s);
      printf("%d",len);
      return 0;
}

Choices:
- if(string[len] == 1) return 1
- if(string[len+1] == 1) return 1
- if(string[len] == ‘\0’) return 0
- if(string[len] == ‘\0’) return 1


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "abcdef";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

Choices:
- 5
- 6
- 7
- 8


Question:
What is the time complexity of the following recursive implementation used to find the length of the string?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "abcdef";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
How many times is the function recursive_get_len() called when the following code is executed?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "adghjkl";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

Choices:
- 6
- 7
- 8
- 9


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "123-1-2-3";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

Choices:
- 3
- 6
- 9
- 10


Question:
What is the output of the following code?
#include<stdio.h>
int get_max_element(int *arr,int n)
{
      int i, max_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] > max_element)
          max_element = arr[i];
      return max_element;
}
int get_min_element(int *arr, int n)
{
      int i, min_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] < min_element)
          min_element = arr[i];
      return min_element;
}
int main()
{
     int n = 7, arr[7] = {5,2,4,7,8,1,3};
     int max_element = get_max_element(arr,n);
     int min_element = get_min_element(arr,n);
     printf("%d %d",max_element,min_element);
     return 0;
}

Choices:
- 5 3
- 3 5
- 8 1
- 1 8


Question:
What is the output of the following code?
#include<stdio.h>
int get_max_element(int *arr,int n)
{
      int i, max_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] > max_element)
          max_element = arr[i];
      return max_element;
}
int get_min_element(int *arr, int n)
{
      int i, min_element;
      for(i = 1; i < n; i++)
        if(arr[i] < min_element)
          min_element = arr[i];
      return min_element;
}
int main()
{
     int n = 7, arr[7] = {1,1,1,0,-1,-1,-1};
     int max_element = get_max_element(arr,n);
     int min_element = get_min_element(arr,n);
     printf("%d %d",max_element,min_element);
     return 0;
}

Choices:
- 1 -1
- -1 1
- 1 Garbage value
- Depends on the compiler


Question:
What is the time complexity of the following iterative implementation used to find the largest and smallest element in an array?
#include<stdio.h>
int get_max_element(int *arr,int n)
{
      int i, max_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] > max_element)
          max_element = arr[i];
      return max_element;
}
int get_min_element(int *arr, int n)
{
      int i, min_element;
      for(i = 1; i < n; i++)
        if(arr[i] < min_element)
          min_element = arr[i];
      return min_element;
}
int main()
{
     int n = 7, arr[7] = {1,1,1,0,-1,-1,-1};
     int max_element = get_max_element(arr,n);
     int min_element = get_min_element(arr,n);
     printf("%d %d",max_element,min_element);
     return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n/2)


Question:
What is the output of the following code?
#include<stdio.h>
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
    int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
    int max_element = recursive_max_element(arr,n,idx);
    int min_element = recursive_min_element(arr,n,idx);
    printf("%d %d",max_element,min_element);
    return 0;
}

Choices:
- -1 10
- 10 -1
- 1 10
- 10 1


Question:
What is the time complexity of the following recursive implementation used to find the largest and the smallest element in an array?
#include<stdio.h>
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
    int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
    int max_element = recursive_max_element(arr,n,idx);
    int min_element = recursive_min_element(arr,n,idx);
    printf("%d %d",max_element,min_element);
    return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
How many times is the function recursive_min_element() called when the following code is executed?
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
     int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
     int min_element = recursive_min_element(arr,n,idx);
     printf("%d",min_element);
     return 0;
}

Choices:
- 9
- 10
- 11
- 12


Question:
What is the output of the following code?
#include<stdio.h>
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
     int n = 5, idx = 0, arr[] = {1,1,1,1,1};
     int max_element = recursive_max_element(arr,n,idx);
     int min_element = recursive_min_element(arr,n,idx);
     printf("%d %d",max_element,min_element);
     return 0;
}

Choices:
- 1 1
- 0 0
- compile time error
- runtime error


Question:
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 = head->next;
	  }
	  return max_num;
}
int main()
{
      int n = 9, arr[9] ={5,1,3,4,5,2,3,3,1},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->next = 0;
          newNode->val = arr[i];
          temp->next =newNode;
          temp = temp->next;
      }
      int max_num = get_max();
      printf("%d %d",max_num);
      return 0;
}

Choices:
- 5
- 1
- runtime error
- garbage value


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

Choices:
- 2 2
- 8 8
- 2 8
- 8 2


Question:
What is the time complexity of the following iterative code used to find the smallest and largest element in a linked list?
#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;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


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

Choices:
- 7 1
- 0 7
- 7 0
- 1 1


Question:
What is the time complexity of the recursive implementation used to find the largest and smallest element in a linked list?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int recursive_get_max(struct Node* temp)
{
      if(temp->next == 0)
        return  temp->val;
      return max_of_two(temp->val,recursive_get_max(temp->next));
}
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_get_min(struct Node* temp)
{
      if(temp->next == 0)
        return  temp->val;
      return min_of_two(temp->val,recursive_get_min(temp->next));
}
int main()
{
     int n = 9, arr[9] ={1,3,2,4,5,0,5,6,7},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->next = 0;
           newNode->val = arr[i];
           temp->next =newNode;
           temp = temp->next;
     }
     int max_num = recursive_get_max(head->next);
     int min_num = recursive_get_min(head->next);
     printf("%d %d",max_num,min_num);
     return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the output of the following code?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_get_min(struct Node* temp)
{
      if(temp->next == 0)
        return  temp->val;
      return min_of_two(temp->val,recursive_get_min(temp->next));
}
int main()
{
     int n = 5, arr[5] ={1,1,1,1,1},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->next = 0;
           newNode->val = arr[i];
           temp->next =newNode;
           temp = temp->next;
     }
     int min_num = recursive_get_min(head->next);
     printf("%d",min_num);
     return 0;
}

Choices:
- 1
- 0
- compile time error
- runtime error


Question:
How many times will the function recursive_get_min() be called when the following code is executed?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_get_min(struct Node* temp)
{
      if(temp->next == 0)
        return  temp->val;
      return min_of_two(temp->val,recursive_get_min(temp->next));
}
int main()
{
     int n = 5, arr[5] ={1,1,1,1,1},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->next = 0;
           newNode->val = arr[i];
           temp->next =newNode;
           temp = temp->next;
     }
     int min_num = recursive_get_min(head->next);
     printf("%d",min_num);
     return 0;
}

Choices:
- 4
- 5
- 6
- 7


Question:
What does the following code do?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
     int i;
     for(i = 0; i < len; i++)
     if(arr[i] == num)
      return i;
     return -1;
}
int main()
{
      int arr[5] ={1,2,3,4,5},num=3,len = 5;
      int indx = search_num(arr,num,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Search and returns the index of all the occurrences of the number that is searched
- Search and returns the index of the first occurrence of the number that is searched
- Search and returns of the last occurrence of the number that is searched
- Returns the searched element from the given array


Question:
What is the output of the following code?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
     int i;
     for(i = 0; i < len; i++)
     if(arr[i] == num)
        return i;
     return -1;
}
int main()
{
      int arr[5] ={1,3,3,3,5},num=3,len = 5;
      int indx = search_num(arr,num,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Index of 3 is 0
- Index of 3 is 1
- Index of 3 is 2
- Index of 3 is 3


Question:
What is the time complexity of the following code used to search an element in an array?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
     int i;
     for(i = 0; i < len; i++)
     if(arr[i] == num)
        return i;
     return -1;
}
int main()
{
      int arr[5] ={1,3,3,3,5},num=3,len = 5;
      int indx = search_num(arr,num,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
     return -1;
     if(arr[idx] == num)
       return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={1,2,3,3,3,5,6,7},num=5,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Index of 5 is 5
- Index of 5 is 6
- Index of 5 is 7
- Index of 5 is 8


Question:
How many times is the function recursive_search_num() called when the following code is executed?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
     return -1;
     if(arr[idx] == num)
     return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={1,2,3,3,3,5,6,7},num=5,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- 5
- 6
- 7
- 8


Question:
What is the time complexity of the following recursive implementation of linear search?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
     return -1;
     if(arr[idx] == num)
     return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={1,2,3,3,3,5,6,7},num=5,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
      return -1;
     if(arr[idx] == num)
      return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={-11,2,-3,0,3,5,-6,7},num = -2,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Index of -2 is 1
- Index of -2 is 0
- Index of -2 is -1
- None of the mentioned


Question:
What does the following code do?
#include<stdio.h>
int cnt = 0;
int recursive_search_num(int *arr, int num, int idx, int len)
{
      int cnt = 0;
      if(idx == len)
      return cnt;
      if(arr[idx] == num)
       cnt++;
      return cnt + recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={0,0,0,0,3,5,-6,7},num = 0,len = 8;
      int ans = recursive_search_num(arr,num,0,len);
      printf("%d",ans);
      return 0;
}

Choices:
- Adds all the indexes of the number 0
- Finds the first last occurrence of the number 0
- Counts the number of occurrences of the number 0
- None of the mentioned


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
        return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
         return mid;
      else if(arr[mid] < num)
         lo = mid + 1;
      else
         hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[8] = {1,2,3,4,5,6,7,8},num = 7,len = 8;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Index of 7 is 4
- Index of 7 is 5
- Index of 7 is 6
- Index of 7 is 7


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
       return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[8] = {0,0,0,0,3,5,6,7},num = 0,len = 8;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Index of 0 is 0
- Index of 0 is 1
- Index of 0 is 2
- Index of 0 is 3


Question:
In which of the below cases will the following code produce a wrong output?
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
       return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}

Choices:
- Array: {0,0,0,0,0,0} Search: -10
- Array: {1,2,3,4,5} Search: 0
- Array: {5,4,3,2,1} Search: 1
- Array: {-5,-4,-3,-2,-1} Search: -1


Question:
How many times is the function recursive_binary_search() called when the following code is executed?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
        return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[5] = {1,2,3,4,5},num = 1,len = 5;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- 0
- 1
- 2
- 3


Question:
What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
        return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
        return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[5] = {5,4,3,2,1},num = 1,len = 5;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Choices:
- Index of 1 is 4
- Index of 1 is 5
- Index of 1 is -1
- Index of 1 is 0


Question:
What does the following code do?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int linear_search(int value)
{
      struct Node *temp = head->next;
      while(temp != 0)
      {
           if(temp->val == value)
              return 1;
           temp = temp->next;
      }
      return 0;
}
int main()
{
      int arr[5] = {1,2,3,4,5};
      int n = 5,i;
      head = (struct Node*)malloc(sizeof(struct Node));
      head->next = 0;
      struct Node *temp;
      temp = head;
      for(i=0; i<n; i++)
      {
           struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
           newNode->next = 0;
           newNode->val = arr[i];
           temp->next = newNode;
           temp = temp->next;
      }
      int ans = linear_search(60);
      if(ans == 1)
      printf("Found");
      else
      printf("Not found");
      return 0;
}

Choices:
- Finds the index of the first occurrence of a number in a linked list
- Finds the index of the last occurrence of a number in a linked list
- Checks if a number is present in a linked list
- Checks whether the given list is sorted or not


Question:
What is the output of the following code?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int linear_search(int value)
{
      struct Node *temp = head->next;
      while(temp != 0)
      {
           if(temp->val == value)
             return 1;
           temp = temp->next;
      }
      return 0;
}
int main()
{
     int arr[5] = {1,2,3,4,5};
     int n = 5,i;
     head = (struct Node*)malloc(sizeof(struct Node));
     head->next = 0;
     struct Node *temp;
     temp = head;
     for(i=0; i<n; i++)
     {
           struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
           newNode->next = 0;
           newNode->val = arr[i];
           temp->next = newNode;
           temp = temp->next;
     }
     int ans = linear_search(-1);
     if(ans == 1)
     printf("Found");
     else
     printf("Not found");
     return 0;
}

Choices:
- Found
- Not found
- Compile time error
- Runtime error


Question:
What is the time complexity of the following implementation of linear search on a linked list?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int linear_search(int value)
{
      struct Node *temp = head->next;
      while(temp != 0)
      {
           if(temp->val == value)
             return 1;
           temp = temp->next;
      }
      return 0;
}
int main()
{
     int arr[5] = {1,2,3,4,5};
     int n = 5,i;
     head = (struct Node*)malloc(sizeof(struct Node));
     head->next = 0;
     struct Node *temp;
     temp = head;
     for(i=0; i<n; i++)
     {
           struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
           newNode->next = 0;
           newNode->val = arr[i];
           temp->next = newNode;
           temp = temp->next;
     }
     int ans = linear_search(-1);
     if(ans == 1)
     printf("Found");
     else
     printf("Not found");
     return 0;
}

Choices:
- O(1)
- O(n)
- O(n2)
- O(n3)


Question:
What is the output of the following code?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int linear_search(int value)
{
      struct Node *temp = head->next;
      while(temp -> next != 0)
      {
            if(temp->val == value)
            return 1;
            temp = temp->next;
      }
      return 0;
}
int main()
{
     int arr[6] = {1,2,3,4,5,6};
     int n = 6,i;
     head = (struct Node*)malloc(sizeof(struct Node));
     head->next = 0;
     struct Node *temp;
     temp = head;
     for(i=0; i<n; i++)
     {
           struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
           newNode->next = 0;
           newNode->val = arr[i];
           temp->next = newNode;
           temp = temp->next;
     }
     int ans = linear_search(60);
     if(ans == 1)
       printf("Found");
     else
       printf("Not found");
     return 0;
}

Choices:
- Found
- Not found
- Compile time error
- Runtime error


Question:
What is the output of the following code?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
     int val;
     struct Node* next;
}*head;
int linear_search(struct Node *temp,int value)
{
      if(temp == 0)
         return 0;
      if(temp->val == value)
         return 1;
      return linear_search(temp->next, value);
}
int main()
{
     int arr[6] = {1,2,3,4,5,6};
     int n = 6,i;
     head = (struct Node*)malloc(sizeof(struct Node));
     head->next = 0;
     struct Node *temp;
     temp = head;
     for(i=0; i<n; i++)
     {
           struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
           newNode->next = 0;
           newNode->val = arr[i];
           temp->next = newNode;
           temp = temp->next;
     }
     int ans = linear_search(head->next,6);
     if(ans == 1)
       printf("Found");
     else
       printf("Not found");
     return 0;
}

Choices:
- Found
- Not found
- Compile time error
- Runtime error