Question: What is true about a break statement ?

Choices:
- Break stops the execution of the entire program
- Break halts the execution and forces the control out of the loop
- Break forces the control out of the loop and starts the execution of next iteration
- Break halts the execution of the loop for certain time frame


Question: The no. of external nodes in a full binary tree with n internal nodes is?

Choices:
- n
- n+1
- 2n
- 2n + 1


Question: Which of the following statements is true?

Choices:
- Recursion is always better than iteration
- Recursion uses more memory compared to iteration
- Recursion uses less memory compared to iteration
- Iteration is always better and simpler than recursion


Question: Consider an implementation of an unsorted singly linked list. Suppose it has its representation with a head pointer only.Given the representation, which of the following operations can be implemented in O(1) time?         i) Insertion at the front of the linked listii) Insertion at the end of the linked listiii) Deletion of the front node of the linked listiv) Deletion of the last node of the linked list

Choices:
- I and II
- I and III
- I, II and III
- I, II, and IV


Question: If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be removed?

Choices:
- ABCD
- DCBA
- DCAB
- ABDC


Question: What is the complexity to insert an element in a Heap?

Choices:
- θ(nlogn)
- θ(n)
- θ(logn)
- θ(1)


Question: Which of these operators can be used to concatenate two or more String objects?


Question: Assume that we use Bubble Sort to sort n distinct elements in ascending order. When does the best case of Bubble Sort occur?

Choices:
- When elements are sorted in ascending order
- When elements are sorted in descending order
- When elements are not sorted by any order
- There is no best case for Bubble Sort. It always takes O(n*n) time


Question:
Quick sort is run on 2 inputs shown below to sort in ascending orderA. 1, 2, 3……n
B. n, n – 1, n – 2 …… 1
Let C1 and C2 be the number of comparisons made for A and B respectively. Then

Choices:
- C1 > C2
- C1 = C2
- C1 < C2
- Cannot say anything for arbitrary n


Question: What is the worst-case complexity of Selection sort algorithm?

Choices:
- O(n)
- O(n^2)
- O(n log(n))
- none


Question: what is the time complexity of the best sorting algorithms?

Choices:
- O(n)
- O(n log(n))
- O(n^2)
- none


Question: Which of the following sorting algorithms has the worst time complexity for most inputs?

Choices:
- Quick sort
- Merge sort
- Bubble sort
- None


Question: Which of the following is not a stable sorting algorithm in its typical implementation?

Choices:
- Quick sort
- Bubble Sort
- Merge sort
- selection sort


Question: How does strcmp() function work to compare two strings?

Choices:
- It compares characters based on their index.
- It compares strings based on the index.
- It compares characters of the string based on their ASCII values.
- None.


Question: Graphs are represented using ___________.

Choices:
- Adjacency list
- Adjacency tree
- Adjacency queue
- None


Question: Which of these methods from the String class is used to extract a single character from an object of String?

Choices:
- CHARAT()
- charAt()
- CharAt()
- charAT()


Question: Which of the following is a palindromic string?

Choices:
- "APPLE"
- "ABCDE"
- "APPLA"
- "ABCCBA"


Question: How can we create a dynamic array in C?

Choices:
- vector( )
- dynamic_array( )
- malloc()
- None


Question: In C++, we can create a dynamic array using the ______keyword.

Choices:
- array
- this
- super
- new


Question:
What will do the below code snippet?

#include <iostream>
using namespace std;

int main()
{
    int m = 3, n = 4, c = 0;

    int* arr = new int[m * n];

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

            *(arr + i * n + j) = ++c;
        }
    }

    return 0;
}

``````C++

Choices:
- It will create a 1d array and assign value to it.
- It will create a 1d array of size m*n and assign value to it.
- It will create a 1d dynamic array and assign value to it.
- It will create a dynamic 2d array and assign value to it.


Question: What is the time complexity for inserting/deleting at the beginning of the array?

Choices:
- O(1)
- O(logN)
- O(NlogN)
- O(N)


Question: Which method is used to access elements in an array?

Choices:
- Sequential
- Random
- Logarithmic
- Alternative


Question: When the array has free unused memory, which method can be used to free up the extra memory?

Choices:
- free()
- shrinkSize()
- growSize()
- None


Question: The First Index of the array always starts from -----

Choices:
- -1
- 1
- 0
- None


Question: When does the ArrayIndexOutOfBoundsException occur?

Choices:
- Compile time
- Run time
- Not an Exception
- None


Question: What is the size of int arr[15]; if we assume that int is 4 bytes?

Choices:
- 15
- 11
- 12
- 60


Question: The function solves a particular problem by calling a copy of itself and solving smaller subproblems of the original problems.

Choices:
- hashing functions
- recursive function
- predefined function
- none


Question: The stack's ____ determines how many recursive calls are allowed.

Choices:
- size
- time
- Quality
- None


Question: What is the advantage of a dynamic array over a static array?

Choices:
- The dynamic array is fixed.
- The dynamic array takes O(n) time.
- The size of the dynamic array is not fixed.
- None


Question: Which of the following is not a backtracking algorithm?

Choices:
- Knight tour problem
- N queen problem
- Tower of Hanoi
- M coloring problem


Question: Backtracking problems take time complexity ......

Choices:
- high time complexity
- Low time complexity
- Both
- None


Question: The method used in dynamic programming to save previously calculated data is known as _______.

Choices:
- Mapping
- Saving value property
- Memoization
- None


Question: When the solutions to the same subproblems are needed repetitively for solving the actual problem, is callled.....

Choices:
- Overlapping Subproblems
- recursive problems
- Optimal problem
- None


Question: How long does it take to calculate the nth Fibonacci number using dynamic programming?

Choices:
- O(n^2)
- O(log n)
- O(n)
- O(2^n)


Question: Dynamic Programming (DP) is defined as a technique that solves some particular type of problems in ....time

Choices:
- Quadratic
- Polynomial
- Linear
- none


Question: what type of additional memory is required for each recursive call.

Choices:
- Queue memory
- heap memory
- stack memory
- None


Question: Which of these tree traversal methods is used to output the contents of a binary tree in ascending order?

Choices:
- Pre-Order
- Monastic Orders
- In-Order
- None of these


Question: The tree that has left value smaller than the root value and right node greater than the root value, is called?

Choices:
- Binary tree
- Binary search tree
- complete tree
- None


Question: A tree data structure is a------ data structure.

Choices:
- Hierarchical
- Pre-defined
- primary
- None


Question: What is the maximum number of edges in an acyclic undirected graph with n vertices?

Choices:
- n
- n -+1
- n - 2
- n - 1


Question: BFS uses which data structure?

Choices:
- stack
- Queue
- Tree
- Hash


Question: Backtracking is generally a method for resolving______ problems.

Choices:
- Numerical problems
- Exhaustive search
- Combinatorial problems
- Graph coloring problems


Question: Which of the following statements about Tries is false?

Choices:
- Tries are space-efficient compared to hash tables.
- Tries can efficiently perform prefix searches.
- Tries are typically used for searching in sorted arrays.
- Tries can handle large dictionaries efficiently.


Question: ________is an advanced data structure based on a trie that is optimized for palindromic strings.

Choices:
- Splay Tree
- B tree
- AVL tree
- Palindromic tree


Question: A self-balancing binary search tree that optimizes for insertions and deletions rather than strict balance is called:

Choices:
- AVL tree
- Red-Black tree
- Splay tree
- B + Tree


Question:
What is the output of the below code?

#include <iostream>
using namespace std;

int main()
{

    string str = "GeeksForGeeks";
    cout << str.substr(2).substr(4);
    return 0;
}

``````C++

Choices:
- eksForGeeks
- ForGEeks
- Geeks
- orGeeks


Question: How many null pointers exist in a circular linked list?

Choices:
- 0
- 1
- 2
- 3


Question: The process of inserting an element in the stack is called ____________

Choices:
- create
- Evaluation
- Push
- Pop


Question: In a stack, if a user tries to remove an element from an empty stack it is called?

Choices:
- Empty collection
- Garbage collection
- Overflow
- Underflow


Question: The list of data in which elements can be inserted and removed at the same end is called ____.

Choices:
- Array
- String
- Stack
- None


Question: which data structure type allows deleting data elements from front and inserting at rear?

Choices:
- Stack
- Queue
- Array
- None


Question: Two Basic Operations used in queue are:

Choices:
- push and pop
- Enqueue & Dequeue
- insert and remove
- None of these


Question: How many queues are needed to implement a stack? Consider the situation where no other data structure like arrays, or linked lists is available to you.

Choices:
- 1
- 2
- 3
- None


Question: The difference between queue and stack is ____.

Choices:
- queues require dynamic memory but stacks do not
- stack requires dynamic memory but queue do not
- queue uses two ends of the structure, stack uses only one
- stack uses two ends of the structure, queue uses only one


Question: A Kind of tree where every node in a tree can have at most two children.

Choices:
- Binary Tree
- Binary Search Tree
- Binary Expression Tree
- None


Question: Which of these methods of class String is used to obtain the length of the String object?

Choices:
- get()
- Sizeof()
- lengthof()
- length()


Question:
What the below program will  Print?

#// C program to find the length of string
#include <bits/stdc++.h>
using namespace std;
int main()
{

    string str = "Hello Geeks";
    int i;
    for (i = 0; str[i] != '\0'; ++i)
        ;
    cout << i;

    return 0;
}

``````C++

Choices:
- 0
- 1
- 5
- 11


Question: In Inorder traversal of a binary tree, the second step is

Choices:
- traverse the right subtree
- visit the root
- traverse the left subtree
- none of these


Question: left-shifting an integer “a” with an integer “b” denoted as ‘(a<<b)’ is equivalent to

Choices:
- multiplying a with 2^b (2 raised to power b).
- adding a to b
- dividing a with 2 raised to power b.
- None


Question: Which bitwise operator can be used to quickly check if a number is even or odd?

Choices:
- | Bitwise OR operator
- & Bitwise AND Operator
- ^ Bitwise Exclusive OR
- ~~ Bitwise Negate Operator


Question: The left-shift and right-shift operators should not be used for ------numbers.

Choices:
- positive
- real
- negative
- None


Question: Which searching technique takes O(1) time complexity for searching the data?

Choices:
- Binary Search
- Linear search
- AVL search tree
- Hashing


Question: In simple chaining, what data structure is used?

Choices:
- Singly linked list
- circular linked list
- Doubly linked list
- Binary trees


Question: What is the situation known as when a key different than the one required is maintained at the specified location?

Choices:
- Collision
- Hashing
- Chaining
- Open Addressing


Question: In Hashing techniques, A key can be ......

Choices:
- integer
- String
- either integer or string
- none


Question: What creates mapping betwwen key and value?

Choices:
- collision
- Key
- Hash Table
- Hash function


Question: which condition is needed to stop the recursion otherwise infinite loop will occur.

Choices:
- Base case
- Best case
- worst case
- None


Question: what issue may occur if the base case is not reached or is not defined?

Choices:
- Program Crashes
- stack underflow
- stack overflow
- none


Question: Which of the following statement is true about Red-Black Tree?P1: Each Leaf Node and the root node of the Red-Black tree is Black.P2:  The children of a Red node is Black.P3: The children of a Black Node is Black.P4: Two adjacent nodes can be Red.

Choices:
- P1 & P4
- P2 & P3
- P1 & P3
- P1 & P2


Question: The condition in which Red-Black trees are preferred over AVL trees?

Choices:
- When tree must be balanced
- When tree must be balanced.
- When tree must be sorted
- When there are more insertions or deletions


Question: What is the time complexity to reverse a string?

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


Question: You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?

Choices:
- Heap sort
- Merge sort
- Quick sort
- Insertion sort


Question: Let A be a square matrix of size n x n. Consider the following program. What is the expected output? C = 100for i = 1 to n do    for j = 1 to n do    {        Temp = A[i][j] + C        A[i][j] = A[j][i]        A[j][i] = Temp - C    } for i = 1 to n do    for j = 1 to n do        Output(A[i][j]);

Choices:
- The matrix A itself
- Transpose of matrix A
- Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A
- None of the above


Question: Which of the following is true about merge sort?

Choices:
- Merge Sort works better than quick sort if data is accessed from slow sequential memory.
- Merge Sort is stable sort by nature
- Merge sort outperforms heap sort in most of the practical situations.
- All of the above.


Question: Let A[1...n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. What is the expected number of inversions in any permutation on n elements ?

Choices:
- n(n-1)/2
- n(n-1)/4
- n(n+1)/4
- 2n[logn]


Question: Consider an array consisting of –ve and +ve numbers. What would be the worst case time complexity of an algorithm to segregate the numbers having same sign altogether i.e all +ve on one side and then all -ve on the other ?

Choices:
- O(N)
- O(N Log N)
- O(N * N)
- O(N Log Log N)


Question: An algorithm performs (logN)1/2 find operations, N insert operations, (logN)1/2 delete operations, and (logN)1/2 decrease-key operations on a set of data items with keys drawn from a linearly ordered set. For a delete operation, a pointer is provided to the record that must be deleted. For the decrease-key operation, a pointer is provided to the record that has its key decreased. Which one of the following data structures is the most suited for the algorithm to use, if the goal is to achieve the best total asymptotic complexity considering all the operations?

Choices:
- Unsorted array
- Min-heap
- Sorted array
- Sorted doubly linked list


Question: The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is

Choices:
- Θ(n)
- Θ(logn)
- Θ(n*logn)
- Θ(1)


Question:
What will the output of the below code?

#include <iostream>
using namespace std;

int main()
{

    int arr[2] = { 1, 2 };
    cout << 0 [arr] << ", " << 1 [arr] << endl;
    return 0;
}

``````Java

public class Main {
    public static void main(String[] args) {
        int[] arr = {1, 2};
        System.out.println(arr[0] + ", " + arr[1]);
    }
}

``````Java

Choices:
- 1, 2
- Syntax error
- Run time error
- None


Question: Which of the following data structures is best suited for efficient implementation of priority queue?

Choices:
- Array
- Linked List
- Heap
- Stack


Question: Consider a situation where a client receives packets from a server.  There may be differences in speed of the client and the server.  Which data structure is best suited for synchronization?

Choices:
- Circular Linked List
- Queue
- Stack
- Priority Queue


Question: Which data structure is best suited for converting recursive implementation to iterative implementation of an algorithm?

Choices:
- Queue
- Stack
- Tree
- Graph


Question: Which among the following data structures is best suited for storing very large numbers (numbers that cannot be stored in long long int).  Following are the operations needed for these large numbers.

Choices:
- Array
- Linked List
- Binary Tree
- Hash


Question: Which sorting algorithms is most efficient to sort string consisting of ASCII characters?

Choices:
- Quick sort
- Heap sort
- Merge sort
- Counting sort


Question:
A data structure is required for storing a set of integers such that each of the following operations can be done in (log n) time, where n is the number of elements in the set.   o	Deletion of the smallest element
   o	Insertion of an element if it is not already present in the set
Which of the following data structures can be used for this purpose?

Choices:
- A heap can be used but not a balanced binary search tree
- A balanced binary search tree can be used but not a heap
- Both balanced binary search tree and heap can be used
- Neither balanced binary search tree nor heap can be used


Question: Given 8 identical coins out of which one coin is heavy and a pan balance. How many minimum number of measurements are needed to find the heavy coin?

Choices:
- 2
- 3
- 4
- 7


Question: The best data structure to check whether an arithmetic expression has balanced parentheses is a  (GATE CS 2004)

Choices:
- queue
- stack
- tree
- list


Question: Which data structure is used in redo-undo feature?

Choices:
- Stack
- Queue
- Tree
- Graph


Question: Which data structure is used for balancing of symbols?

Choices:
- Stack
- Queue
- Tree
- Graph


Question: Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time to Q2. Then which one of the following is consistent with the above statement?

Choices:
- Q1 is in NP, Q2 is NP hard
- Q2 is in NP, Q1 is NP hard
- Both Q1 and Q2 are in NP
- Both Q1 and Q2 are in NP hard


Question: Ram and Shyam have been asked to show that a certain problem Π is NP-complete. Ram shows a polynomial time reduction from the 3-SAT problem to Π, and Shyam shows a polynomial time reduction from Π to 3-SAT. Which of the following can be inferred from these reductions ?

Choices:
- Π is NP-hard but not NP-complete
- Π is in NP, but is not NP-complete
- Π is NP-complete
- Π is neither NP-hard, nor in NP


Question:
Consider the following two problems on undirected graphs
α : Given G(V, E), does G have an independent set of size | V | - 4?
β : Given G(V, E), does G have an independent set of size 5?

Which one of the following is TRUE?

Choices:
- α is in P and β is NP-complete
- α is NP-complete and β is in P
- Both α and β are NP-complete
- Both α and β are in P


Question: Consider the decision problem 2CNFSAT defined as follows:

Choices:
- NP-Complete.
- solvable in polynomial time by reduction to directed graph reachability.
- solvable in constant time since any input instance is satisfiable.
- NP-hard, but not NP-complete.


Question: Suppose a polynomial time algorithm is discovered that correctly computes the largest clique in a given graph. In this scenario, which one of the following represents the correct Venn diagram of the complexity classes P, NP and NP Complete (NPC)?

Choices:
- A
- B
- C
- D


Question:
Which of the following statements are TRUE?
1. The problem of determining whether there exists
   a cycle in an undirected graph is in P.
2. The problem of determining whether there exists
   a cycle in an undirected graph is in NP.
3. If a problem A is NP-Complete, there exists a
   non-deterministic polynomial time algorithm to solve A.

Choices:
- 1, 2 and 3
- 1 and 2 only
- 2 and 3 only
- 1 and 3 only


Question:
Which of the following statements are TRUE?
(1) The problem of determining whether there exists a cycle in an undirected graph is in P.
(2) The problem of determining whether there exists a cycle in an undirected graph is in NP.
(3) If a problem A is NP-Complete, there exists a non-deterministic polynomial time algorithm to solve A.

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


Question: The problem 3-SAT and 2-SAT are

Choices:
- both in P
- both NP complete
- NP-complete and in P respectively
- undecidable and NP-complete respectively


Question: Let X be a problem that belongs to the class NP. Then which one of the following is TRUE?

Choices:
- There is no polynomial time algorithm for X.
- If X can be solved deterministically in polynomial time, then P = NP.
- If X is NP-hard, then it is NP-complete.
- X may be undecidable.


Question: Which data structure is most efficient to find the top 10 largest items out of 1 million items stored in file?

Choices:
- Min heap
- Max heap
- BST
- Sorted array


Question: In a village, people build houses in the same side of the road. A thief plans to loot the village. He wants maximum amount of money without having any risk of getting caught. By some means, the villagers know that their adjacent house is being looted or not and thus they become alert. So the thief cannot loot contiguous two houses. Given that the thief knows the amount of money stored in each house and the road is straight and there is no turning, which is the most efficient algorithmic strategy to solve this problem?

Choices:
- Brute-force
- Dynamic Programming
- Backtracking
- Divide and Conquer


Question: Which of the following is not an in-place algorithm?

Choices:
- Insertion sort
- Selection sort
- Merge sort
- Heap sort


Question:
A set X can be represented by an array x[n] as follows:  Consider the following algorithm in which x,y, and z are Boolean arrays of size n:

algorithm zzz(x[] , y[], z [])
{
   int i;
   for (i=O; i<n; ++i)
     z[i] = (x[i] ^ ~y[i]) V (~x[i] ^ y[i]) }

``````C

The set Z computed by the algorithm is:

Choices:
- (X Intersection Y)
- (X Union Y)
- (X-Y) Intersection (Y-X)
- (X-Y) Union (Y-X)


Question:
Suppose you are given an array s[1...n] and a procedure reverse (s,i,j) which reverses the order of elements in a between positions i and j (both inclusive). What does the following sequence
do, where 1 < k <= n:
  reverse (s, 1, k);
  reverse (s, k + 1, n);
  reverse (s, 1, n);

(GATE CS 2000)

Choices:
- Rotates s left by k positions
- Leaves s unchanged
- Reverses all elements of s
- None of the above


Question:
Consider the following C function.

float f(float x, int y)
{
  float p, s; int i;
  for (s=1, p=1, i=1; i < y; i ++)
  {
    p*= x/i;
    s+=p;
  }
  return s;
}

``````c

For large values of y, the return value of the function f best approximates (GATE CS 2003)

Choices:
- x^y
- e^x
- ln(1 + x)
- x^x


Question: Let A be a square matrix of size n x n. Consider the following program. What is the expected output? C = 100for i = 1 to n do    for j = 1 to n do    {        Temp = A[i][j] + C        A[i][j] = A[j][i]        A[j][i] = Temp - C    } for i = 1 to n do    for j = 1 to n do        Output(A[i][j]);

Choices:
- The matrix A itself
- Transpose of matrix A
- Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A
- None of the above


Question: A three dimensional array in ‘C++’ is declared as int A[x][y][z]. Consider that array elements are stored in row major order and indexing begins from 0. Here, the address of an item at the location A[p][q][r] can be computed as follows (where w is the word length of an integer):

Choices:
- &A[0][0][0] + w(y * z * q + z * p + r)
- &A[0][0][0] + w(y * z * p + z*q + r)
- &A[0][0][0] + w(x * y * p + z * q+ r)
- &A[0][0][0] + w(x * y * q + z * p + r)


Question: Which of the following correctly declares an array?

Choices:
- int geeks[20];
- int geeks;
- geeks{20};
- array geeks[20];


Question:
An array A consists of n integers in locations A[0], A[1] ....A[n-1]. It is required to shift the elements of the array cyclically to the left by k places, where 1 <= k <= (n-1). An incomplete algorithm for doing this in linear time, without using another array is given below. Complete the algorithm by filling in the blanks. Assume alt the variables are suitably declared.

min = n; i = 0;

while (___________) {

     temp = A[i]; j = i;

     while (________) {

     A[j] = ________

     j= (j + k) mod n ;

     If ( j< min ) then

         min = j;

}

A[(n + i — k) mod n] = _________

i = __________

``````C++

Choices:
- i > min; j!= (n+i)mod n; A[j + k]; temp; i + 1 ;
- i < min; j!= (n+i)mod n; A[j + k]; temp; i + 1;
- i > min; j!= (n+i+k)mod n; A[(j + k)]; temp; i + 1;
- i < min; j!= (n+i-k)mod n; A[(j + k)mod n]; temp; i + 1;


Question: Consider a two dimensional array A[20][10]. Assume 4 words per memory cell, the base address of array A is 100, elements are stored in row-major order and first element is A[0][0]. What is the address of A[11][5] ?

Choices:
- 560
- 460
- 570
- 575


Question:
Consider a list of recursive algorithms and a list of recurrence relations as shown below. Each recurrence relation corresponds to exactly one algorithm and is used to derive the time complexity of the algorithm.
   Recursive Algorithm  Recurrence Relation     P. Binary search I. T(n) = T(n-k) + T(k) + cn   Q. Merge sort II. T(n) = 2T(n-1) + 1   R. Quick sort III. T(n) = 2T(n/2) + cn   S. Tower of Hanoi IV. T(n) = T(n/2) + 1

Choices:
- P-II, Q-III, R-IV, S-I
- P-IV, Q-III, R-I, S-II
- P-III, Q-II, R-IV, S-I
- P-IV, Q-II, R-I, S-III


Question:
Let f(n) = n and g(n) = n(1+sin n), where n is a positive integer. Which of the following statements is/are correct?
I.  f(n) = O(g(n))
II. f(n) = Ω(g(n))

Choices:
- Only I
- Only II
- Both I and II
- Neither I nor II


Question:
Select the correct asymptotic complexity of an algorithm with runtime T(n, n) where
T(x, c) = Θ(x) for c <= 2,
T(c, y) = Θ(y) for c <= 2, and
T(x, y) = Θ(x+y) + T(x/2, y/2)

Choices:
- Θ(nLogn)
- Θ(n2)
- Θ(n)
- Θ(n2Logn)


Question:
Consider the following three functions.

f1 = 10n
f2 = nlogn
f3 = n√n

Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?

Choices:
- f3,f2,f1
- f2,f1,f3
- f1,f2,f3
- f2,f3,f1


Question: The solution to the recurrence equation T(2k) = 3 T(2k-1) + 1, T (1) = 1, is:

Choices:
- 2k
- (3k + 1 - 1)/2
- 3log2k
- 2log3k


Question:
Consider the following recurrence relation

The value of T(m2) for m ≥ 1 is

Choices:
- (m/6) (21m - 39) + 4
- (m/6) (4m2  - 3m + 5)
- (m/2) (m2.5 - 11m + 20) - 5
- (m/6) (5m3 - 34m2 + 137m - 104) + (5/6)


Question:
The worst-case running time of Merge sort algorithm is described by the following recurrence relation :

                 ⌈ 1               , if n = 1
       T(n)  =   | 2T(n/2)+ n      , otherwise
                 ⌊

Given recurrence equation evaluates to -

Choices:
- 2k  T(n/2k) + kn
- 2k  T(nk/2) + kn
- nk  T(n/2k)
- T(n/2k) + kn


Question:
Which one of the following correctly determines the solution of the recurrence relation with T(1) = 1?
T(n) = 2T(n/2) + Logn

Choices:
- Θ(n)
- Θ(nLogn)
- Θ(n*n)
- Θ(log n)


Question: Which of the following sequences of array elements forms a heap?

Choices:
- {23, 17, 14, 6, 13, 10, 1, 12, 7, 5}
- {23, 17, 14, 6, 13, 10, 1, 5, 7, 12}
- {23, 17, 14, 7, 13, 10, 1, 5, 6, 12}
- {23, 17, 14, 7, 13, 10, 1, 12, 5, 7}


Question: A complete binary min-heap is made by including each integer in [1, 1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth 0. The maximum depth at which integer 9 can appear is _____________

Choices:
- 6
- 7
- 8
- 9


Question: An operator delete(i) for a binary heap data structure is to be designed to delete the item in the i-th node. Assume that the heap is implemented in an array and i refers to the i-th index of the array. If the heap tree has depth d (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?

Choices:
- O(1)
- O(d) but not O(1)
- O(2d) but not O(d)
- O(d2d) but not O(2d)


Question: Consider the following array of elements. 〈89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100〉. The minimum number of interchanges needed to convert it into a max-heap is

Choices:
- 4
- 5
- 2
- 3


Question: Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4.  Now consider that a value 35 is inserted into this heap. After insertion, the new heap is

Choices:
- 40, 30, 20, 10, 15, 16, 17, 8, 4, 35
- 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
- 40, 30, 20, 10, 35, 16, 17, 8, 4, 15
- 40, 35, 20, 10, 15, 16, 17, 8, 4, 30


Question: Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i <= n), the index of the parent is

Choices:
- i - 1
- floor(i/2)
- ceiling(i/2)
- (i+1)/2


Question: A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:

Choices:
- 10, 8, 7, 3, 2, 1, 5
- 10, 8, 7, 2, 3, 1, 5
- 10, 8, 7, 1, 2, 3, 5
- 10, 8, 7, 5, 3, 2, 1


Question: Which of the following Binary Min Heap operation has the highest time complexity?

Choices:
- Inserting an item under the assumption that the heap has capacity to accommodate one more item
- Merging with another heap under the assumption that the heap has capacity to accommodate items of other heap
- Deleting an item from heap
- Decreasing value of a key


Question: Given two max heaps of size n each, what is the minimum possible time complexity to make a one max-heap of size from elements of two max heaps?

Choices:
- O(n^2)
- O(nLogLogn)
- O(n)
- O(nLogn)


Question: An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array (GATE CS 2006)

Choices:
- Solves it in linear time using a left to right pass of the array
- Solves it in linear time using a right to left pass of the array
- Solves it using divide and conquer in time 8(nlogn)
- Solves it in time 8(n2)


Question: Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and S is polynomial-time reducible to R. Which one of the following statements is true? (GATE CS 2006)

Choices:
- R is NP-complete
- R is NP-hard
- Q is NP-complete
- Q is NP-hard


Question: An inversion in a an array A[] is a pair (A[i], A[j]) such that A[i] > A[j] and i < j. An array will have maximum number of inversions if it is:

Choices:
- Sorted in increasing order
- Sorted in decreasing order
- Sorted in alternate fashion
- Both A and B


Question: In general, in a recursive and non-recursive implementation of a problem (program) :

Choices:
- Both time and space complexities are better in recursive than in non-recursive program.
- Both time and space complexities are better in non-recursive than in recursive program
- Time complexity is better in recursive version but space complexity is better in non-recursive version of the program.
- Space complexity is better in recursive version but time complexity is better in non-recursive version of the program.


Question:
What will be the output of the following JAVA program?

class GFG
{
   static int d=1;
   static void count(int n)
    {
    System.out.print(n+" ");
    System.out.print(d+" ");
    d++;
    if(n > 1) count(n-1);
    System.out.print(d+" ");
  }

 public static void main(String args[])
    {
       count(3);
    }
}

``````Java

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


Question: Which is the Bit Toggling operator below.?

Choices:
- Bitwise OR operator( | )
- Bitwise XOR Operator (^)
- Bitwise AND Operator(&)
- TILDE operator(~)


Question: What is the output of the below expression? 000111 | 01010

Choices:
- 0000000
- 00
- 010111
- None


Question: Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.

Choices:
- True
- False


Question: If we have to add two numbers without having any carry, which bitwise operator should be used?

Choices:
- Bitwise OR |
- Bitwise AND &
- Bitwise NOT ~
- None


Question:
Predict the output:

#include <iostream>
using namespace std;

int main()
{
    int x = -5;
    x = x >> 1;
    cout << x << endl;
    return 0;
}

``````C++

Choices:
- -2
- -3
- Error
- -1


Question:
What is the output of the below code?

#include <bits/stdc++.h>
using namespace std;
int main()
{
    if (~0 == 1)
        cout << "Yes";
    else
        cout << "No";
}

``````C++

Choices:
- Yes
- No
- Error
- None


Question:
What will the below code do?

void function(int& num, int pos)
{
   num |= (1 << pos);
}

``````C++

Choices:
- divide num by pos.
- Multiply num by pos.
- Add num with pos.
- set the given position (pos) of a number (num).


Question:
What will the output of the following code for N = 5 and K =2?

bool function(int n, int k)
{
    bool bit = n & (1 << k);
    return bit;
}

``````C++

Choices:
- 0
- 2
- 5
- 1


Question: The average number of key comparisons done in a successful sequential search in a list of length n is

Choices:
- log n
- (n-1)/2
- n/2
- (n+1)/2


Question:
Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending order.

int ProcessArray(int *listA, int x, int n)
{
    int i, j, k;
    i = 0;
    j = n-1;
    do
    {
        k = (i+j)/2;
        if (x <= listA[k])
            j = k-1;
        if (listA[k] <= x)
            i = k+1;
    }
    while (i <= j);
    if (listA[k] == x)
        return(k);
    else
        return -1;
}

``````C

Which one of the following statements about the function ProcessArray is CORRECT?

Choices:
- It will run into an infinite loop when x is not in listA.
- It is an implementation of binary search.
- It will always find the maximum element in listA.
- It will return −1 even when x is present in listA.


Question: Consider a sorted array of n numbers and a number x. What would be the time complexity of the best known algorithm to find a triplet with sum equal to x. For example, arr[] = {1, 5, 10, 15, 20, 30}, x = 40. Then there is a triplet {5, 15, 20} with sum 40.

Choices:
- O(n)
- O(n^2)
- O(n Log n)
- O(n^3)


Question: Which is the format specifier used to prefix 0x and print a number in hexadecimal notation.?

Choices:
- %O
- %x
- %#x


Question: The average case occurs in the Linear Search Algorithm when:

Choices:
- The item to be searched is in some where middle of the Array
- The item to be searched is not in the array
- The item to be searched is in the last of the array
- The item to be searched is either in the last or not in the array


Question: Which of the following is the correct recurrence for the worst case of Ternary Search?

Choices:
- T(n) = T(n/3) + 4, T(1) = 1
- T(n) = T(n/2) + 2,  T(1) = 1
- T(n) = T(n + 2) + 2,  T(1) = 1
- T(n) = T(n - 2) + 2,  T(1) = 1


Question:
1. f(int Y[10], int x) {
2.     int i, j, k;
3.     i = 0; j = 9;
4.     do {
5.             k =  (i + j) /2;
6.             if( Y[k] < x)  i = k; else j = k;
7.         } while(Y[k] != x && i < j);
8.     if(Y[k] == x) printf ("x is in the array ") ;
9.     else printf (" x is not in the array ") ;
10. }

``````C++

In the above question, the correction needed in the program to make it work properly is (GATE CS 2008)

Choices:
- Change line 6 to: if (Y[k] < x) i = k + 1; else j = k-1;
- Change line 6 to: if (Y[k] < x) i = k - 1; else j = k+1;
- Change line 6 to: if (Y[k] <= x) i = k; else j = k;
- Change line 7 to: } while ((Y[k] == x) && (i < j));


Question: Given a sorted array of integers, what can be the minimum worst-case time complexity to find ceiling of a number x in given array? The ceiling of an element x is the smallest element present in array which is greater than or equal to x. Ceiling is not present if x is greater than the maximum element present in array. For example, if the given array is {12, 67, 90, 100, 300, 399} and x = 95, then the output should be 100.

Choices:
- O(loglogn)
- O(n)
- O(log(n))
- O(log(n) * log(n))


Question: Which of the following is correct recurrence for worst case of Binary Search?

Choices:
- T(n) = 2T(n/2) + O(1) and T(1) = T(0) = O(1)
- T(n) = T(n-1) + O(1) and T(1) = T(0) = O(1)
- T(n) = T(n/2) + O(1) and T(1) = T(0) = O(1)
- T(n) = T(n-2) + O(1) and T(1) = T(0) = O(1)


Question: Linear search is also called------

Choices:
- Random Search
- Sequential search
- Perfect search
- None


Question: The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is.

Choices:
- a
- b
- c
- d


Question: What are the necessary condition for a Tree to be a heap?

Choices:
- the tree must be complete.
- Every Root value is greater or smaller than the children's value.
- Both A and B
- None


Question:
Consider the following recurrence.

T(n) = T([Tex]\\sqrt{n}[/Tex]) + [Tex]\\Theta(Log Log n)[/Tex]

What is the value of recurrence?

(A) [Tex]\\Theta( (Log Log n) ^ 2)[/Tex]
(B) [Tex]\\Theta(Log Log n)[/Tex]
(B) [Tex]\\Theta(n)[/Tex]
(B) [Tex]\\Theta(Log Log Log n)[/Tex]

Choices:
- A
- B
- C
- D


Question:
Consider the following recurrence
T(n) = 3T(n/5) + lgn * lgn

What is the value of T(n)?

(A) [Tex]\\Theta(n ^ \\log_5{3})[/Tex]
(B) [Tex]\\Theta(n ^ \\log_3{5})[/Tex]
(c) [Tex]\\Theta(n Log n )[/Tex]
(D) [Tex]\\Theta( Log n )[/Tex]

Choices:
- A
- B
- C
- D


Question:
The time complexity of the following C function is (assume n > 0 (GATE CS 2004)

int recursive (mt n)
{
   if (n == 1)
     return (1);
   else
     return (recursive (n-1) + recursive (n-1));
}

``````c

Choices:
- 0(n)
- 0(nlogn)
- 0(n^2)
- 0(2^n)


Question:
What is the time complexity of the following recursive function:

int DoSomething (int n)
{
  if (n <= 2)
    return 1;
  else
    return (DoSomething (floor(sqrt(n))) + n);
}

``````c

(A) [Tex]\\theta   [/Tex](n) (B) [Tex]\\theta   [/Tex](nlogn)(C) [Tex]\\theta   [/Tex](logn)(D) [Tex]\\theta   [/Tex](loglogn)

Choices:
- A
- B
- D
- C


Question: The increasing order of performance  of the searching algorithms are:

Choices:
- linear search  <  jump search  <  binary search
- linear search  >  jump search  <  binary search
- linear search  <  jump search  >  binary search
- linear search  >  jump search  >  binary search


Question:
What is the output of the below code for input num = 15?

unsigned int fun(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}

``````C++

Choices:
- 15
- 5
- 4
- 3


Question: Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder and preorder traversal. Respectively, of a complete binary tree. Which of the following is always true? (GATE CS 2000)

Choices:
- LASTIN = LASTPOST
- LASTIN = LASTPRE
- LASTPRE = LASTPOST
- None of the above


Question: The array representation of a complete binary tree contains the data in sorted order. Which traversal of the tree will produce the data in sorted form?

Choices:
- Preorder
- Inorder
- Postorder
- Level order


Question:
Consider the following recursive JAVA function. If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?

static void get (int n){
  if (n < 1)
    return;
  get(n - 1);
  get(n - 3);
  System.out.print(n);
}

``````Java

Choices:
- 15
- 25
- 35
- 45


Question:
Consider the following C function.

int fun (int n){
  int x = 1, k;
  if (n == 1)
    return x;
  for (k = 1; k < n; ++k)
     x = x + fun(k) * fun(n – k);
  return x;
}

``````C

The return value of fun(5) is __________.

Choices:
- 0
- 26
- 51
- 71


Question:
Consider the following C function:

int f(int n)
{
   static int i = 1;
   if (n >= 5)
      return n;
   n = n+i;
   i++;
   return f(n);
}

``````C

The value returned by f(1) is

Choices:
- 5
- 6
- 7
- 8


Question:
Consider the JAVA function given below.

static  int f(int j){
  int i = 50;
  int k;
  if (i == j){
    System.out.print("something");
    k = f(i);
    return 0;
  }
  else return 0;
}

``````Java

Which one of the following is TRUE?

Choices:
- The function returns 0 for all values of j.
- The function prints the string something for all values of j.
- The function returns 0 when j = 50.
- The function will exhaust the runtime stack or run into an infinite loop when j = 50


Question:
Output of following program?

#include <stdio.h>
int fun(int n, int *f_p)
{
    int t, f;
    if (n <= 1)
    {
        *f_p = 1;
        return 1;
    }
    t = fun(n- 1,f_p);
    f = t+ * f_p;
    *f_p = t;
    return f;
}

int main()
{
    int x = 15;
    printf (\" %d \\n\", fun(5, &x));
    return 0;
}

``````C

Choices:
- 6
- 8
- 14
- 15


Question:
Predict the Output:

class GFG
{
  static int f(int a[],int i, int n)
  {
    if(n <= 0) return 0;
    else if(a[i] % 2 == 0) return a[i] + f(a, i+1, n-1);
    else return a[i] - f(a, i+1, n-1);
  }
   public static void main(String args[])
    {
      int a[] = {12, 7, 13, 4, 11, 6};
      System.out.print(f(a,0,6));
    }
}

``````Java

Choices:
- -9
- 5
- 15
- 19


Question:
Consider the same recursive C++ function that takes two arguments

unsigned int foo(unsigned int n, unsigned int r)
{
    if (n > 0)
        return (n % r + foo(n / r, r));
    else
        return 0;
}

``````C++

What is the return value of the function foo when it is called as foo(513, 2)?

Choices:
- 9
- 8
- 5
- 2


Question: A B-Tree used as an index for a large database table has four levels including the root node. If a new key is inserted in this index, then the maximum number of nodes that could be newly created in the process are:

Choices:
- 5
- 4
- 3
- 2


Question: Consider B+ tree in which the search key is 12 bytes long, block size is 1024 bytes, record pointer is 10 bytes long and block pointer is 8 bytes long. The maximum number of keys that can be accommodated in each non-leaf node of the tree is

Choices:
- 49
- 50
- 51
- 52


Question: With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the root node) that must be fetched in order to satisfy the following query: “Get all records with a search key greater than or equal to 7 and less than 15” is ________

Choices:
- 4
- 5
- 6
- 7


Question: A B+ -tree index is to be built on the Name attribute of the relation STUDENT. Assume that all student names are of length 8 bytes, disk block are size 512 bytes, and index pointers are of size 4 bytes. Given this scenario, what would be the best choice of the degree (i.e. the number of pointers per node) of the B+ -tree?

Choices:
- 16
- 42
- 43
- 44


Question:
Consider the following 2-3-4 tree (i.e., B-tree with a minimum degree of two) in which each data item is a letter. The usual alphabetical ordering of letters is used in constructing the tree.

What is the result of inserting G in the above tree ?

A)

B)

C)

D) None of the above

Choices:
- A
- B
- C
- D


Question: The order of a leaf node in a tree B+ ? is the maximum number of (value, data record pointer) pairs it can hold. Given that the block size is 1K bytes, data record pointer is 7 bytes long, the value field is 9 bytes long and a block pointer is 6 bytes long, what is the order of the leaf node?

Choices:
- 63
- 64
- 67
- 68


Question: A B-tree of order 4 is built from scratch by 10 successive insertions. What is the maximum number of node splitting operations that may take place?

Choices:
- 3
- 4
- 5
- 6


Question: B+ trees are preferred to binary trees in databases because (GATE CS 2000)

Choices:
- Disk capacities are greater than memory capacities
- Disk access is much slower than memory access
- Disk data transfer rates are much less than memory data transfer rates
- Disks are more reliable than memory


Question: Which one of the following is a key factor for preferring B-trees to binary search trees for indexing database relations?

Choices:
- Database relations have a large number of records
- Database relations are sorted on the primary key
- B-trees require less memory than binary search trees
- Data transfer form disks is in blocks.


Question: Consider a B+-tree in which the maximum number of keys in a node is 5. What is the minimum number of keys in any non-root node? (GATE CS 2010)

Choices:
- 1
- 2
- 3
- 4


Question: A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-order and the values in each node printed out, the sequence of values obtained is 5, 3, 1, 2, 4, 6, 8, 7. If the tree is traversed in post-order, the sequence obtained would be

Choices:
- 8, 7, 6, 5, 4, 3, 2, 1
- 1, 2, 3, 4, 8, 7, 6, 5
- 2, 1, 4, 3, 6, 7, 8, 5
- 2, 1, 4, 3, 7, 8, 6, 5


Question: The numbers 1, 2, .... n are inserted in a binary search tree in some order. In the resulting tree, the right subtree of the root contains p nodes. The first number to be inserted in the tree must be

Choices:
- p
- p + 1
- n - p
- n - p + 1


Question: Which one of the following binary trees has its inorder and preorder traversals as BCAD  and ABCD, respectively?

Choices:
- A
- B
- C
- D


Question: Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder and preorder traversal, respectively, of a complete binary tree. Which of the following is always true?

Choices:
- LASTIN = LASTPOST
- LASTIN = LASTPRE
- LASTPRE = LASTPOST
- None of the above


Question:
Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely ?
(i)     preorder and postorder
(ii)    inorder and postorder
(iii)   preorder and inorder
(iv)   level order and postorder

Choices:
- (i) only
- (ii), (iii)
- (iii) only
- (iv) only


Question: Level order traversal of a rooted tree can be done by starting from the root and performing

Choices:
- preorder traversal
- inorder traversal
- depth first search
- breadth first search


Question:
Consider the pseudocode given below. The function DoSomething() takes as argument a pointer to the root of an arbitrary tree represented by the leftMostChild-rightSibling representation.
Each node of the tree is of type treeNode.

typedef struct treeNode* treeptr;
struct treeNode
{
    treeptr leftMostChild, rightSibling;
};
int DoSomething (treeptr tree)
{
    int value=0;
    if (tree != NULL)
    {
        if (tree->leftMostChild == NULL)
            value = 1;
        else
            value = DoSomething(tree->leftMostChild);
        value = value + DoSomething(tree->rightSibling);
    }
    return(value);
}

``````C

When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned by the function corresponds to the

Choices:
- number of internal nodes in the tree.
- height of the tree.
- number of nodes without a right sibling in the tree.
- number of leaf nodes in the tree.


Question:
Consider the following rooted tree with the vertex P labeled as root

The order in which the nodes are visited during in-order traversal is

Choices:
- SQPTRWUV
- SQPTURWV
- SQPTWUVR
- SQPTRUWV


Question:
Consider the code fragment written in C below :

void f (int n)
{
    if (n <= 1)  {
        printf (\"%d\", n);
    }
    else {
        f (n/2);
        printf (\"%d\", n%2);
    }
}

``````C

Which of the following implementations will produce the same output for f(173) as the above code? P1

void f (int n)
{
    if (n/2)  {
        f(n/2);
    }
    printf (\"%d\", n%2);
}

``````C

P2

void f (int n)
{
    if (n <=1)  {
        printf (\"%d\", n);
    }
    else {
        printf (\"%d\", n%2);
        f (n/2);
    }
}

``````C

Choices:
- Both P1 and P2
- P2 only
- P1 only
- Neither P1 nor P2


Question:
The running time of the following algorithm

  Procedure A(n)
  If n <= 2 return(1) else return A([Tex]\\lceil \\sqrt{n}  \\rceil[/Tex]);

is best described by

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


Question:
The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed
void find_and_replace(char *A, char *oldc, char *newc) {
    for (int i = 0; i < 5; i++)
       for (int j = 0; j < 3; j++)
           if (A[i] == oldc[j]) A[i] = newc[j];
}
 The procedure is tested with the following four test cases
(1) oldc = "abc", newc = "dab"
(2) oldc = "cde", newc =  "bcd"
(3) oldc  = "bca", newc  = "cda"
(4) oldc = "abc", newc = "bac"
The tester now tests the program on all input strings of length five consisting of characters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw?

Choices:
- Only one
- Only two
- Only three
- All four


Question: The minimum number of interchanges needed to convert the array 89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70 into a heap with the maximum element at the root is

Choices:
- 0
- 1
- 2
- 3


Question: How much time a heap will take to Find Min/Max value?

Choices:
- O(logN)
- O(N)
- O(1)
- None


Question:
Let A be a matrix of size n x n. Consider the following program. What is the expected output?

void fun(int A[][N])
{
    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            swap(A[i][j], A[j][i]);
}

``````C++

Choices:
- Matrix A
- Diagonal Of matrix A
- Transpose of matrix A
- None


Question:
What is the correct way to call the function (fun) in the below program?

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

void fun(char* arr)
{
    int i;
    unsigned int n = strlen(arr);
    for (i = 0; i < n; i++)
        cout << " " << arr[i];
}

// Driver program
int main()
{
    char arr[]
        = { 'g', 'e', 'e', 'k', 's', 'q', 'u', 'i', 'z' };
    // How to call the above function here to print the char
    // elements?

    return 0;
}

``````C++

Choices:
- fun(&arr);
- fun(*arr);
- fun(arr)
- None


Question:
What will the output of the below code, be if the base address of the array is 1200?

#include <iostream>
using namespace std;

int main()
{

    int arr[] = { 1, 2, 3, 4, 5 };
    cout << arr << ", " << &arr << ", " << &arr[0] << endl;
    return 0;
}

``````C++

Choices:
- 1200, 1202, 1204
- 1200 1200 1200
- 1200, 1204, 1208
- 1200, 1204, 1208


Question: A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

Choices:
- An array of 50 numbers
- An array of 100 numbers
- An array of 500 numbers
- A dynamically allocated array of 550 numbers


Question:
Consider the following recurrence relation.

Which one of the following options is correct?

Choices:
- T(n) = Θ(n5/2)
- T(n) = Θ(nlogn)
- T(n) = Θ(n)
- T(n) = Θ((logn)5/2)


Question:
The running time of an algorithm is given by

T(n) = T(n-1) + T(n-2) — T(n-3), if n > 3
     = n, otherwise

Then what should be the relation between T(1), T(2) and T(3), so that the order of the algorithm is constant ?

Choices:
- T(1) = T(2) = T(3)
- T(1) + T(3) = 2 * T(2)
- T(1) - T(3) = T(2)
- T(1) + T(2) = T(3)


Question:
What is the time complexity for the following C module? Assume that n>0 .
int module(int n)
{
if (n == 1)
return 1;
else
return (n + module(n-1));
}

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


Question: Consider the following recurrence: T(n) = 2T(n1/2) + 1 T(1) = 1 Which of the following is true?

Choices:
- T(n)= O(log log n)
- T(n) = O(log n)
- T(n) = O(n1/2)
- T(n)= O(n)


Question:
Match the following and choose the correct answer in the order A, B, C

  A. Heap Construction p. O(n log n)   B. Hash table construction with linear probing q. O(n2)   C. AVL Tree construction r. O(n)

(Bounds given may or may not be asymptotically tight)

Choices:
- q, r, p
- p, q, r
- q, p, r
- r, q, p


Question:
The recurrence relation T(1) = 2
 T(n) = 3T(n/4)+n
has the solution, T(n) equals to

Choices:
- O(n)
- O(log n)
- O(n^3/4)
- None of the above


Question: What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size n?

Choices:
- Θ(√n)
- Θ(log2(n))
- Θ(n2)
- Θ(n)


Question: When n = 22k for some k ≥ 0, the recurrence relationT(n) = √(2) T(n/2) + √n, T(1) = 1evaluates to :

Choices:
- √(n) (log n + 1)
- √(n) (log n )
- √(n) log √(n)
- n log √(n)


Question: What are the applications of the Heap data structure?

Choices:
- Medical Applications
- File Compression
- Stock market
- All of these


Question: Which languages necessarily need heap allocation in the run time environment?

Choices:
- Those that support recursion
- Those that use dynamic scoping
- Those that use global variables
- Those that allow dynamic data structures


Question: Suppose we are sorting an array of eight integers using heapsort, and we have just finished some heapify (either maxheapify or minheapify) operations. The array now looks like this: 16 14 15 10 12 27 28 How many heapify operations have been performed on root of heap?

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


Question: Let H be a binary min-heap consisting of n elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in H?

Choices:
- Θ(1)
- Θ(logn)
- Θ(n)
- Θ(nlogn)


Question: Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is _________ .

Choices:
- 510
- 511
- 512
- 255


Question: Given a binary-max heap. The elements are stored in an arrays as 25, 14, 16, 13, 10, 8, 12. What is the content of the array after two delete operations?

Choices:
- 14,13,8,12,10
- 14,12,13,10,8
- 14,13,12,8,10
- 14,13,12,10,8


Question: The number of nodes of height h in any n - element heap is __________.

Choices:
- h
- 2h
- ceil(n/2h)/
- ceil(n/2h+1)


Question: Which one of the following array represents a binary max-heap?

Choices:
- [26, 13, 17, 14, 11, 9, 15]
- [26, 15, 14, 17, 11, 9, 13]
- [26, 15, 17, 14, 11, 9, 13]
- [26, 15, 13, 14, 11, 9, 17]


Question: Which of the following is a valid heap ? A 16 14 10 4 7 9 3 2 8 1B 16 14 10 8 7 9 3 2 4 1 C 16 14 10 8 1 9 3 2 4 7D 16 14 3 4 1 9 10 8 2 7

Choices:
- A
- B
- C
- D


Question:
Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm

int n, rev;
rev = 0;
while (n > 0)
{
   rev = rev*10 + n%10;
   n = n/10;
}

``````C

The loop invariant condition at the end of the ith iteration is:

Choices:
- n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1
- n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1
- n != rev
- n = D1D2….Dm and rev = DmDm-1…D2D1


Question:
Let T(n) be the function defined by T(1)= 1, T(n)= 2T (⌊n/2⌋) + √n  for n≥2. Which of the following statement(s) is true?

a.  T(n) = O(√n)
b.  T(n) = O(n)
c.  T(n) = O(log n)
d. None of the above

Choices:
- a
- b
- c
- d


Question:
What will do the following code?

void fun(int arr[], int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            for (int k = i; k <= j; k++)
                cout << arr[k] << " ";

            cout << endl;
        }
    }
}

``````C++

Choices:
- Prints the subsequence of the article.
- Prints the elements of the array
- Prints the subarray of the element.
- None


Question: Which of the following is the limitation of the array?

Choices:
- elements can be accessed from anywhere.
- The size of the array is fixed.
- Indexing is started from Zero.
- Memory waste if an array's elements are smaller than the size allotted to them


Question:
Consider the below program, and what is doing this program basically?

#include <bits/stdc++.h>
using namespace std;

void print(char a[], int n, int ind)
{
    for (int i = ind; i < n + ind; i++)
        cout << a[(i % n)] << " ";
}

int main()
{
    char a[] = { 'A', 'B', 'C', 'D', 'E', 'F' };
    int n = sizeof(a) / sizeof(a[0]);
    print(a, n, 3);
    return 0;
}

``````C++

Choices:
- It is printing the normal array
- It is printing circular array rotated by 3
- Syntax error
- None


Question:
Match the following:List - IList - II(a) Fibonacci Search(i) O(N)(b) Jump Search(ii) O(√N)(c) Sentinel Linear Search(iii) O(log2(log2 n))(d) Interpolation Search(iv) F(n) = F(n-1) + F(n-2)
Hints: (a)(b)(c)(d)(1)(i)(iv)(iii)(ii)(2)(iv)(i)(ii)(iii)(3)(i)(iv)(ii)(iii)(4)(iv)(ii)(i)(iii)

Choices:
- (1)
- (2)
- (3)
- (4)


Question: In the worst case, (for instance where the numerical values of the keys increase exponentially) the interpolation search technique will take how many comparisons.?

Choices:
- O(N)
- O(logN)
- O(loglogN)
- None


Question: How many comparisons are required in the worst case a traditional linear search utilizes?

Choices:
- N
- N + 1
- 2N
- N + 2


Question: What is the time complexity for performing Jump search?

Choices:
- O(LogN)
- O(N)
- O(N^2)
- O(√N)


Question: What is sentinel value in Sentinel Linear Search?

Choices:
- The middle element
- The second element
- The last element
- None


Question: A list of n strings, each of length n, is sorted into lexicographic order using merge - sort algorithm. The worst case running time of this computation is :

Choices:
- O(n log n)
- O(n2log n)
- O(n2 + log n)
- O(n3)


Question:
Consider a 2D-array  A[10][20] using row major order in memory and the memory location we want to access is A[y, z]. Known that each memory address occupies 4-bytes.
Below is the 3-address code for the same, fill the blank spaces with correct value :

x : A[y, z]

t1 = ---(1)--- * ---(2)---
t2 = t1  +  z
t3 = t2  *  ---(3)---
---(4)--- = base address of A
x = t4[---(5)---]

Choices:
-
(1) : x
(2) : 10
(3) : 4
(4) : t4
(5) : t3
-
(1) : y
(2) : 10
(3) : t4
(4) : 4
(5) : t3
-
(1) : y
(2) : 20
(3) : 4
(4) : t4
(5) : t3
- None of these


Question: What is the value of

Choices:
- -1
- 1
- 0
- π


Question:
A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with ∞, and hence there cannot be any entry to the right of, or below a ∞. The following Young tableau consists of unique entries.

1     2     5      14
3     4     6      23
10    12    18     25
31    ∞     ∞       ∞

When an element is removed from a Young tableau, other elements should be moved into its place so that the resulting table is still a Young tableau (unfilled entries may be filled in with a ∞). The minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is ____________

Choices:
- 2
- 5
- 6
- 18


Question:
A data structure is required for storing a set of integers such that each of the following operations can be done in (log n) time, where n is the number of elements in the set.
   o	Delection of the smallest element
   o	Insertion of an element if it is not already present in the set

Which of the following data structures can be used for this purpose?

Choices:
- A heap can be used but not a balanced binary search tree
- A balanced binary search tree can be used but not a heap
- Both balanced binary search tree and heap can be used
- Neither balanced binary search tree nor heap can be used


Question: An Abstract Data Type (ADT) is:

Choices:
- Same as an abstract class
- A data type that cannot be instantiated
- A data type for which only the operations defined on it can be used, but none else
- All of the above


Question: Which data structure in a compiler is used for managing information about variables and their attributes?

Choices:
- Abstract syntax tree
- Symbol table
- Semantic stack
- Parse Table


Question:
Insert the characters of the string K R P C S N Y T J M into a hash table of size 10. Use the hash functionh(x) = ( ord(x) – ord("A") + 1 ) mod10
If linear probing is used to resolve collisions, then the following insertion causes collision

Choices:
- Y
- C
- M
- P


Question: What is the probability of a collision when hashing n keys into a hash table of size m, assuming that the hash function produces a uniform random distribution?

Choices:
- O(1/n)
- O(n/m)
- O(logn)
- O(m/n)


Question: Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5.

Choices:
- 5
- 6
- 7
- 10


Question: Which of the following statement(s) is TRUE?A hash function takes a message of arbitrary length and generates a fixed length code.A hash function takes a message of fixed length and generates a code of variable length.A hash function may give the same hash value for distinct messages.

Choices:
- I only
- II and III only
- I and III only
- II only


Question: Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020?

Choices:
- h(i) = (12 ∗ i) mod 10
- h(i) = (11 ∗ i2) mod 10
- h(i) =i3 mod 10
- h(i) =i2 mod 10


Question: Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?

Choices:
- (97 × 97 × 97)/1003
- (99 × 98 × 97)/1003
- (97 × 96 × 95)/1003
- (97 × 96 × 95)/(3! × 1003)


Question: Which of the following hash functions is most likely to cause clustering in a hash table?

Choices:
- h(k) = k % m
- h(k) = floor(m * (kA mod 1))
- h(k) = k
- h(k) = ((k / m) + k * m) + k % m


Question: How many different insertion sequences of the key values using the hash function h(k) = k mod 10 and linear probing will result in the hash table shown below?

Choices:
- 10
- 20
- 30
- 40


Question:
Consider the below program. What is the expected output?

void fun(int arr[], int start, int end)
{
    while (start < end) {
        int temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}

``````C++

Choices:
- swapping the elements pairwise
- sorting the elements
- Reverse an array
- None


Question: Refer the below diagram and identify the problem.

Choices:
- Normal traversal of the matrix.
- Row-wise traversal of the matrix.
- Column-wise traversal of the matrix.
- spiral traversal of the matrix.


Question:
Fill in the blanks for completing the program to rotate an array by d elements.

/*Function to left rotate arr[] of size n by d*/
void Rotate(int arr[], int d, int n)
{
    int p = 1;
    while (_______) {
        int last = arr[0];
        for (int i = 0; ______ i++) {
            arr[i] = arr[i + 1];
        }
        __________
        p++;
    }
}

``````C++

Choices:
- p <= d , i < n - 1 , arr[n - 1] = last;
- p < d, i < n, arr[n] = last;
- p >=d, i >n , arr[n] =  last
- None


Question:
We are given 9 tasks T1, T2.... T9. The execution of each task requires one unit of time. We can execute one task at a time. Each task Ti has a profit Pi and a deadline di Profit Pi is earned if the task is completed before the end of the dith unit of time.
Task     T1  T2	 T3  T4  T5  T6	 T7 T8  T9
Profit   15  20	 30  18  18  10	 23 16  25
Deadline 7   2 	 5   3 	 4   5 	 2  7   3

What is the maximum profit earned?

Choices:
- 147
- 165
- 167
- 175


Question: In the above question, if array A is made to hold the string “abcde”, which of the above four test cases will be successful in exposing the flaw in this procedure?

Choices:
- None
- 2 only
- 3 and 4 only
- 4 only


Question:
We are given 9 tasks T1, T2.... T9. The execution of each task requires one unit of time. We can execute one task at a time. Each task Ti has a profit Pi and a deadline di Profit Pi is earned if the task is completed before the end of the dith unit of time.
Task     T1  T2	 T3  T4  T5  T6	 T7 T8  T9
Profit   15  20	 30  18  18  10	 23 16  25
Deadline 7   2 	 5   3 	 4   5 	 2  7   3

Are all tasks completed in the schedule that gives maximum profit?

Choices:
- All tasks are completed
- T1 and T6 are left out
- T1 and T8 are left out
- T4 and T6 are left out


Question: Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is ___.

Choices:
- 4
- 6
- 8
- 10


Question: Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the reversal ordering on natural numbers i.e. 9 is assumed to be smallest and 0 is assumed to be largest. The in-order traversal of the resultant binary search tree is

Choices:
- 9, 8, 6, 4, 2, 3, 0, 1, 5, 7
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- 0, 2, 4, 3, 1, 6, 5, 9, 8, 7
- 9, 8, 7, 6, 5, 4, 3, 2, 1, 0


Question: Let G be a simple undirected graph. Let TD be a depth first search tree of G. Let TB be a breadth first search tree of G. Consider the following statements. (I) No edge of G is a cross edge with respect to TD. (A cross edge in G is between two nodes neither of which is an ancestor of the other in TD). (II) For every edge (u, v) of G, if u is at depth i and v is at depth j in TB, then ∣i − j∣ = 1. Which of the statements above must necessarily be true?

Choices:
- I only
- II only
- Both I and II
- Neither I nor II


Question:
The post-order traversal of a binary search tree is given by 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12.
Then the pre-order traversal of this tree is:

Choices:
- 2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20
- 7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12
- 7, 2, 6, 8, 9, 10, 20, 17, 19, 15, 16, 12
- 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20


Question: Which of following option is not correct regarding depth first searching?

Choices:
- In a depth-first traversal of a graph G with V vertices, E edges are marked as tree edges. The number of connected components in G is (E - V).
- Depth-first search requires O(V^2) time if implemented with an adjacency matrix.
- Depth-first search requires O(V + E) time if implemented with adjacency lists
- None of these


Question:
Which of the following sequences denotes the post order traversal sequence of the given tree?
         a
       /   \\
      b     e
     / \\   /
    c  d  f
   /
  g

Choices:
- f e g c d b a
- g c b d a f e
- g c d b f e a
- f e d g c b a


Question: A complete n-ary tree is one in which every node has 0 or n sons. If x is the number of internal nodes of a complete n-ary tree, the number of leaves in it is given by

Choices:
- x(n-1)+1
- xn-1
- xn+1
- x(n+1)


Question: Which of the following statement is false?

Choices:
- A tree with n nodes has (n-1) edges.
- A labeled rooted binary tree can be uniquely constructed given its postorder and preorder traversal results.
- A complete binary tree with n internal nodes has (n+1) leaves.
- The maximum number of nodes in a binary tree of height h is (2^(h+1)  -1).


Question:
Consider the following sequence of nodes for the undirected graph given below.

a b e f d g c
a b e f c g d
a d g e b c f
a d b c g e f
A Depth First Search (DFS) is started at node a. The nodes are listed in the order they are first visited. Which all of the above is (are) possible output(s)?

Choices:
- 1 and 3 only
- 2 and 3 only
- 2, 3 and 4 only
- 1, 2, and 3


Question: Which of the following is correct?

Choices:
- B-trees are for storing data on disk and B+ trees are for main memory.
- Range queries are faster on B+ trees.
- B-trees are for primary indexes and B+ trees are for secondary indexes.
- The height of a B+ tree is independent of the number of records.


Question: B+ Trees are considered BALANCED because

Choices:
- the lengths of the paths from the root to all leaf nodes are all equal.
- the lengths of the paths from the root to all leaf nodes differ from each other by at most 1.
- the number of children of any two non-leaf sibling nodes differ by at most 1.
- the number of records in any two leaf nodes differ by at most 1.


Question: In a file which contains 1 million records and the order of the tree is 100, then what is the maximum number of nodes to be accessed if B+ tree index is used?

Choices:
- 5
- 4
- 3
- 10


Question: The in-order and pre-order traversal of a binary tree are d b e a f c g and a b d e c f g respectively. The post order traversal of a binary tree is

Choices:
- e d b g f c a
- e d b f g c a
- d e b f g c a
- d e f g b c a


Question: A B-Tree used as an index for a large database table has four levels including the root node. If a new key is inserted in this index, then the maximum number of nodes that could be newly created in the process are

Choices:
- 5
- 4
- 1
- 2


Question: Which of the following is FALSE about B/B+ tree

Choices:
- B/B+ trees grow upward while Binary Search Trees grow downward.
- Time complexity of search operation in B/B+ tree is better than Red Black Trees in general.
- Number of child pointers in a B/B+ tree node is always equals to number of keys in it plus one.
- A B/B+ tree is defined by a term minimum degree.  And minimum degree depends on hard disk block size, key and address sizes.


Question: The necessary condition for using binary search in an array is :-

Choices:
- The array should not be too long
- The array should of more size
- The array should be sorted
- None of these


Question: Number of comparisons required for an unsuccessful search of an element in a sequential search, organized, fixed length, symbol table of length L is

Choices:
- L
- L/2
- (L+1)/2
- 2L


Question:
Match the following:List - IList - II(a) Sequential Search(i) Dynamic programming principle(b)Branch - and - bound(ii) repeatedly double index(c) Exponential Search(iii) O(LogN)(d) Binary Search(iv)O(N)
codes: (a)(b)(c)(d)(1)(i)(iv)(iii)(ii)(2)(iv)(i)(ii)(iii)(3)(i)(iv)(ii)(iii)(4)(iv)(ii)(i)(iii)

Choices:
- (1)
- (2)
- (3)
- (4)


Question: The time taken by binary search algorithm to search a key in a sorted array of n elements is

Choices:
- O ( log2n )
- O ( n )
- O ( n log2n )
- O ( n^2)


Question: Which of the following statements is true for Branch - and - Bound search?

Choices:
- Underestimates of remaining distance may cause deviation from optimal path.
- Overestimates can\'t cause right path to be overlooked.
- Dynamic programming principle can be used to discard redundant partial paths.
- All of the above


Question: Suppose there are 11 items in sorted order in an array. How many searches are required on the average, if binary search is employed and all searches are successful in finding the item?

Choices:
- 3.00
- 3.46
- 2.81
- 3.33


Question: The recurrence relation that arises in relation with the complexity of binary search is:

Choices:
- T(n) = 2T(n/ 2) + k , where k is constant
- T(n) = T(n / 2) + k , where k is constant
- T(n) = T(n / 2) + log n
- T(n) = T(n / 2) + n


Question:
Consider the following program that attempts to locate an element x in a sorted array a[ ] using binary search. Assume N>1. The program is erroneous. Under what conditions does the program fail?var i,j,k: integer;  x: integer;
    a: array; [1....N] of integer;
begin	i:= 1; j:= N;
repeat
    k:(i+j) div 2;
    if a[k] < x then i:= k
    else j:= k
until (a[k] = x) or (i >= j);

if (a[k] = x) then
    writeln (\'x is in the array\')
else
    writeln (\'x is not in the array\')
end;

Choices:
- x is the last element of the array a[]
- x is greater than all elements of the array a[]
- Both of the Above
- x is less than the last element of the array a[]


Question: The given diagram shows the flowchart for a recursive function A(n). Assume that all statements, except for the recursive calls, have O(1) time complexity. If the worst case time complexity of this function is O(nα), then the least possible value (accurate up to two decimal positions) of α is __________

Choices:
- 2.2 to 2.4
- 3.2 to 3.4
- 0  to 1.8
- 1


Question:
Consider the recurrence relation a1 = 8,  an = 6n2 + 2n + an-1. Let a99 = k x 104.  The value of K is _____

Note : This question was asked as Numerical Answer Type.

Choices:
- 190
- 296
- 198
- 200


Question: The order of an internal node in a B+ tree index is the maximum number of children it can have. Suppose that a child pointer takes 6 bytes, the search field value takes 14 bytes, and the block size is 512 bytes. What is the order of the internal node?

Choices:
- 24
- 25
- 26
- 27


Question:
Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous. (GATE CS 2008)

1.   f(int Y[10], int x) {
2.     int i, j, k;
3.     i = 0; j = 9;
4.     do {
5.             k =  (i + j) /2;
6.             if( Y[k] < x)  i = k; else j = k;
7.         } while(Y[k] != x && i < j);
8.     if(Y[k] == x) printf (\"x is in the array \") ;
9.     else printf (\" x is not in the array \") ;
10. }

``````C

On which of the following contents of Y and x does the program fail?

Choices:
- Y is [1 2 3 4 5 6 7 8 9 10] and x < 10
- Y is [1 3 5 7 9 11 13 15 17 19] and x < 1
- Y is [2 2 2 2 2 2 2 2 2 2] and x > 2
- Y is [2 4 6 8 10 12 14 16 18 20] and 2 < x < 20 and x is even


Question:
what is the name of the below searching Algorithm?

int function(vector<int> arr,int x){
	int n = arr.size();

	if(n == 0)
		return -1;

	// Find range for binary search by repeatedly doubling i
	int i = 1;
	while(i < n and arr[i] < x)
		i *= 2;

	// Perform binary search on the range [i/2, min(i, n-1)]
	int left = i /2;
	int right = min(i, n-1);

	while(left <= right){
		int mid = (left + right)/2;

		if(arr[mid] == x) return mid;
		else if(arr[mid] < x) left = mid + 1;
		else right = mid - 1;
	}

	return -1;
}

``````C++

Choices:
- Linear Search
- Sequential Search
- Jump  Search
- Exponential Search


Question:
Consider the following tree

If the post order traversal gives ab-cd*+ then the label of the nodes 1,2,3,… will be

Choices:
- +,-,*,a,b,c,d
- a,-,b,+,c,*,d
- a,b,c,d,-,*,+
- -,a,b,+,*,c,d


Question:
Consider the following C function in which size is the number of elements in the array E:

The value returned by the function MyX is the

int MyX(int *E, unsigned int size)
{
    int Y = 0;
    int Z;
    int i, j, k;
    for(i = 0; i < size; i++)
        Y = Y + E[i];
    for(i = 0; i < size; i++)
        for(j = i; j < size; j++)
        {
            Z = 0;
            for(k = i; k <= j; k++)
                Z = Z + E[k];
            if (Z > Y)
                Y = Z;
        }
    return Y;
}

``````C

Choices:
- maximum possible sum of elements in any sub-array of array E.
- maximum element in any sub-array of array E.
- sum of the maximum elements in all possible sub-arrays of array E
- the sum of all the elements in the array E.


Question:
What is the return value of following function for 484?  What does it to in general?

bool fun(int n)
{
    int sum = 0;
    for (int odd = 1; n > sum; odd = odd+2)
       sum = sum + odd;
    return (n == sum);
}

``````C

Choices:
- False, it checks whether a given number is power of 3
- False, it checks whether a given number is even or not
- False, it checks whether a given number is odd or not
- True, it checks whether a given number is perfect square.


Question:
You are given an array with even integer elements. You and some other player take turns to pick numbers. Each player can pick either the leftmost element or the rightmost number. Find the maximum possible score (sum of numbers chosen) by you.
For example: if array is 5 8 4 2, then player you can choose either 5 or 2. Suppose you choose 2, then the other player can choose 5 or 4. Irrespective of what player 2 chooses, in next round you will have chance to choose 8. Thus, maximum possible score by player you, in this scenario, is (8+2)=10.
This problem can efficiently solved using?

Choices:
- Greedy Algorithm
- Dynamic Programming
- Backtracking
- Recursion.


Question: Which of the following is the best possible time complexity to get Nth Fibonacci number with O(1) extra space

Choices:
- Time complexity T(n) is T(n-1) + T(n-2) which is exponential
- O(n)
- O(Logn)
- O(n^2)


Question: There are 25 horses among which you need to find out the fastest 3 horses. You can conduct race among at most 5 to find out their relative speed. At no point you can find out the actual speed of the horse in a race. Find out how many races are required to get the top 3 horses.

Choices:
- 5
- 7
- 8
- 9


Question:
Consider the below program, what operation is performed below:

void fun(int arr[], int n)
{

	if (n == 1)
		return;

	int count = 0;
	for (int i=0; i<n-1; i++)
		if (arr[i] > arr[i+1]){
			swap(arr[i], arr[i+1]);
			count++;
		}
		return;
	fun(arr, n-1);
}

``````C++

Choices:
- Insertion Sort Recursively
- Bubble Sort Recursively
- Selection Sort Recursively
- None


Question: Match the pairs in the following questions: List 1List 2A. Recursion1. Sorted ArrayB. Binary Seach2. RecursionC. Sorting3 Base caseD. Dynamic Programming4.O(NlogN)

Choices:
- A – 2, B – 1, C – 4, D – 3
- A – 3, B – 4, C – 1, D – 2
- A – 3, B – 1, C – 4, D – 2
- A – 2, B – 4, C – 1, D – 3


Question:
Consider the below Program and identify the problem:

void fun2(int arr[], int start_index, int end_index)
{
    if (start_index >= end_index)
        return;
    int min_index;
    int temp;
    min_index = minIndex(arr, start_index, end_index);
    swap(arr[start_index], arr[min_index]);
    fun2(arr, start_index + 1, end_index);
}

``````C++

Choices:
- Selection Sort Recursive implementation
- Bubble sort Recursive implementation
- Finding Pair Recursive implementation
- None of these


Question:
What is the output of the following code for the input arr[]={1,2,3,4,5,6} N=6?

int fun(int A[], int N)
{
	if (N <= 0)
		return 0;
	return (fun(A, N - 1) + A[N - 1]);
}

``````C++

Choices:
- 21
- 0
- Runtime error
- None


Question:
What is the output of the below program for the tree:Tree

void printInorder(struct Node* node)
{
    if (node == NULL)
        return;

    printInorder(node->left);
    cout << node->data << " ";
    printInorder(node->right);
}

``````C++

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


Question:
What is the name of below recursive program?

void fun(int n, char from_rod, char to_rod,
				char aux_rod)
{
	if (n == 0) {
		return;
	}
	fun(n - 1, from_rod, aux_rod, to_rod);
	cout << "Move disk " << n << " from rod " << from_rod
		<< " to rod " << to_rod << endl;
	fun(n - 1, aux_rod, to_rod, from_rod);
}

``````C++

Choices:
- N Queen Problem
- Tower of Hanoi
- M coloring Problem
- None


Question:
What is the output of the following program?

#include <stdio.h>

void print(int n, int j)
{
    if (j >= n)
        return;
    if (n - j > 0 && n - j >= j)
       printf("%d %d\n", j, n-j);
   print(n, j+1);
}

int main()
{
    int n = 8;
    print(n, 1);
}

``````C++

Choices:
- 1 72 63 54 44 4
- 1 72 63 54 4
- 1 72 63 5
- 1 23 45 67 8


Question:
Consider the code fragment written in JAVA below :

void f (int n)
{
  if (n <=1)  {
   System.out.print(n);
  }
  else {
   f (n/2);
   System.out.print(n%2);
  }
}

``````Java

What does f(173) print?

Choices:
- 010110101
- 010101101
- 10110101
- 10101101


Question:
The function f is defined as follows:

int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

``````C

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.1. The function f terminates for finitely many different values of n ≥ 1. ii. The function f terminates for infinitely many different values of n ≥ 1. iii. The function f does not terminate for finitely many different values of n ≥ 1. iv. The function f does not terminate for infinitely many different values of n ≥ 1. Which one of the following options is true of the above?

Choices:
- (i) and (iii)
- (i) and (iv)
- (ii) and (iii)
- (ii) and (iv)


Question:
The solution of the recurrence relation
T(m) = T(3m / 4) + 1 is :

Choices:
- θ (lg m)
- θ (m)
- θ (mlg m)
- θ (lglg m)


Question: Which of the following is an NP-hard problem that can be approximated using a greedy algorithm?

Choices:
- Set cover problem
- Traveling salesman problem
- Knapsack problem
- Minimum spanning tree problem


Question: Assuming P != NP, which of the following is true ? (A) NP-complete = NP(B) NP-complete [Tex]\\cap [/Tex]P = [Tex]\\Phi [/Tex](C) NP-hard = NP(D) P = NP-complete

Choices:
- A
- B
- C
- D


Question: Which of the following is true about NP-Complete and NP-Hard problems.

Choices:
- If we want to prove that a problem X is NP-Hard, we take a known NP-Hard problem Y and reduce Y to X
- The first problem that was proved as NP-complete was the circuit satisfiability problem.
- NP-complete is a subset of NP Hard
- All of the above
- None of the above


Question: Let SHAM3 be the problem of finding a Hamiltonian cycle in a graph G = (V,E) with V divisible by 3 and DHAM3 be the problem of determining if a Hamiltonian cycle exists in such graphs. Which one of the following is true?

Choices:
- Both DHAM3 and SHAM3 are NP-hard
- SHAM3 is NP-hard, but DHAM3 is not
- DHAM3 is NP-hard, but SHAM3 is not
- Neither DHAM3 nor SHAM3 is NP-hard


Question:
Consider the following two problems of graph.

1)   Given a graph, find if the graph has a cycle that visits every vertex exactly once except the first visited vertex which must be visited again to complete the cycle.

2)  Given a graph, find if the graph has a cycle that visits every edge exactly once.

Which of the following is true about above two problems.

Choices:
- Problem 1 belongs NP Complete set and 2 belongs to P
- Problem 1 belongs to P set  and 2 belongs to NP Complete set
- Both problems belong to P set
- Both problems belong to NP complete set


Question: A problem in NP is NP-complete if

Choices:
- It can be reduced to the 3-SAT problem in polynomial time
- The 3-SAT problem can be reduced to it in polynomial time
- It can be reduced to any other problem in NP in polynomial time
- Some problem in NP can be reduced to it in polynomial time


Question:
Given the following statements:
S1 : Every context-sensitive language L is recursive
S2 : There exists a recursive language that is not context-sensitive
Which statements are true?

Choices:
- Only S1 is correct
- Only S2 is correct
- Both S1 and S2 are not correct
- Both S1 and S2 are correct


Question: The problems 3-SAT and 2-SAT are

Choices:
- Both NP-complete
- Both in P
- NP-complete and in P, respectively
- Undecidable and NP-complete, respectively


Question: For problems X and Y, Y is NP-complete and X reduces to Y in polynomial time. Which of the following is TRUE?

Choices:
- If X can be solved in polynomial time, then so can Y
- X is NP-complete
- X is NP-hard
- X is in NP, but not necessarily NP-complete


Question:
Language L1 is polynomial time reducible to language L2. Language L3 is polynomial time reducible to L2, which in turn is polynomial time reducible to language L4. Which of the following is/are True?
I. If L4 ∈ P, L2 ∈ P
II. If L1 ∈ P or L3 ∈ P, then L2 ∈ P
III. L1 ∈ P, if and only if L3 ∈ P
IV. If L4 ∈ P, then L1 ∈ P and L3 ∈ P

Choices:
- II only
- III only
- I and IV only
- I only


Question:
Suppose there are  ⌈ log n ⌉ sorted lists of ⌊ n/log n ⌋ elements each. The time complexity of producing a sorted list of all these elements is :
(Hint : Use a heap data structure)

Choices:
- O(n log log n)
- θ(n log n)
- Ω(n log n)
- Ω(n3/2)


Question: In a min-heap with n elements with the smallest element at the root, the 7th smallest element can be found in time:

Choices:
- theta(nlogn)
- theta(n)
- theta(logn)
- theta(1)


Question:
The most appropriate matching for the following pairs
X: depth first search            1: heap
Y: breadth-first search          2: queue
Z: sorting                       3: stack

is (GATE CS 2000):

Choices:
- X—1 Y—2 Z-3
- X—3 Y—1 Z-2
- X—3 Y—2 Z-1
- X—2 Y—3 Z-1


Question: A min- Heap is a complete binary tree.

Choices:
- True
- False


Question: Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort?

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


Question: You have an array of n elements. Suppose you implement quick sort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is

Choices:
- O(n2)
- O(n*log(n))
- Theta(n*log(n))
- O(n3)


Question: Let P be a QuickSort Program to sort numbers in ascending order using the first element as pivot. Let t1 and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?

Choices:
- t1 = 5
- t1 < t2
- t1 > t2
- t1 = t2


Question: Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then

Choices:
- T(n) <= 2T(n/5) + n
- T(n) <= T(n/5) + T(4n/5) + n
- T(n) <= 2T(4n/5) + n
- T(n) <= 2T(n/2) + n


Question: In quick sort, for sorting n elements, the (n/4)th smallest element is selected as a pivot using an O(n) time algorithm. What is the worst-case time complexity of the quick sort?(A) θ(n)(B) θ(n*log(n))(C) θ(n^2)(D) θ(n^2 log n)

Choices:
- A
- B
- C
- D


Question: A machine needs a minimum of 100 sec to sort 1000 names by quick sort. The minimum time needed to sort 100 names will be approximately

Choices:
- 50.2 sec
- 6.7 sec
- 72.7 sec
- 11.2 sec


Question:
Suppose we have a O(n) time algorithm that finds median of an unsorted array.

Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot.  What will be the worst case time complexity of this modified QuickSort.

Choices:
- O(n^2 Logn)
- O(n^2)
- O(n Logn Logn)
- O(nLogn)


Question: Which one of the following in place sorting algorithms needs the minimum number of swaps?

Choices:
- Quick sort
- Insertion sort
- Selection sort
- Heap sort


Question: Given an array where numbers are in range from 1 to n6,  which sorting algorithm can be used to sort these number in linear time?

Choices:
- Not possible to sort in linear time
- Radix Sort
- Counting Sort
- Quick Sort


Question: Which of the following is true about merge sort?

Choices:
- Merge Sort works better than quick sort if data is accessed from slow sequential memory.
- Merge Sort is stable sort by nature
- Merge sort outperforms heap sort in most of the practical situations.
- All of the above.


Question: Which sorting algorithm will take the least time when all elements of the input array are identical? Consider typical implementations of sorting algorithms.

Choices:
- Insertion Sort
- Heap sort
- Merge Sort
- Selection sort


Question: Which of the following sorting algorithms in its typical implementation gives best performance when applied on an array which is sorted or almost sorted (maximum 1 or two elements are misplaced).

Choices:
- Quick Sort
- Heap Sort
- Merge Sort
- Insertion Sort


Question: In a permutation a1.....an of n distinct integers, an inversion is a pair (ai, aj) such that i < j and ai > aj. What would be the worst-case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of 1.....n with at most n inversions?

Choices:
- Θ (n2)
- Θ (n*log(n))
- Θ (n1.5)
- Θ (n)


Question: "I\'m a Geek and this question was in asked Sudo Placement 2". The sentence above is an example of a ___________ statement.

Choices:
- figurative
- collateral
- literal
- figurine


Question:
Find the odd one out in the following group of words.
tree, paper, mouse, man

Choices:
- tree
- paper
- mouse
- man


Question:
Select the pair that best expresses a relationship similar to that expressed in the below pair:
Children : Pediatrician

Choices:
- Adult : Orthopaedist
- Females : Gynaecologist
- Kidney : Dermatologist
- Skin : Nephrologist


Question: Choose the word that is opposite in the meaning to the word Lucid.

Choices:
- Vague
- Explicit
- Evident
- Obvious


Question:
Fill in the blank by choosing the correct option:

He had a pleasant experience ______ he was at home.

Choices:
- and
- while
- but
- because


Question:
Choose the correct one-word substitution for the given sentence.

That which cannot be corrected

Choices:
- Incorrigible
- Indelible
- Illegible
- Unintelligible


Question:
Choose the appropriate word from the given options to fill up the blank.

This lake was not a ----- one but a man-made reservoir.

Choices:
- usual
- ordinary
- normal
- natural


Question:
Dhoni plays cricket and Football also.

Choose the correct option to be replaced with the word "also" in the above sentence.

Choices:
- too
- both
- besides
- no improvement


Question:
Since 2001, there is no earthquakes in Gujrat.

Choose the correct option to be replaced with the word "is" in the above sentence.

Choices:
- are
- have been
- were being
- No improvement


Question: Which of the following option is correct?

Choices:
- She was the oldest of the two sisters.
- I will write to you after I shall arrive.
- He has changed bags twice during the last six months.
- The summer has set out, and the days are getting warm.


Question: Which of the following sorting algorithms has the lowest worst-case complexity?

Choices:
- Merge Sort
- Bubble Sort
- Quick Sort
- Selection Sort


Question: Which of the following sorting algorithms has the lowest worst-case complexity?

Choices:
- Merge Sort
- Bubble Sort
- Quick Sort
- Selection Sort


Question:
Which of the following changes to typical QuickSort improves its performance on average and are generally done in practice.1) Randomly picking up to make worst case less
   likely to occur.
2) Calling insertion sort for small sized arrays
   to reduce recursive calls.
3) QuickSort is tail recursive, so tail call
   optimizations can be done.
4) A linear time median searching algorithm is used
   to pick the median, so that the worst case time
   reduces to O(nLogn)

Choices:
- 1 and 2
- 2, 3, and 4
- 1, 2 and 3
- 2, 3 and 4


Question: Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting n(≥ 2) numbers? In the recurrence equations given in the options below, c is a constant.

Choices:
- T(n) = 2T (n/2) + cn
- T(n) = T(n – 1) + T(0) + cn
- T(n) = 2T (n – 2) + cn
- T(n) = T(n/2) + cn


Question:
Consider a list of recursive algorithms and a list of recurrence relations as shown below. Each recurrence relation corresponds to exactly one algorithm and is used to derive the time complexity of the algorithm.
   Recursive Algorithm  Recurrence Relation     P. Binary search I. T(n) = T(n-k) + T(k) + cn   Q. Merge sort II. T(n) = 2T(n-1) + 1   R. Quick sort III. T(n) = 2T(n/2) + cn   S. Tower of Hanoi IV. T(n) = T(n/2) + 1

Choices:
- P-II, Q-III, R-IV, S-I
- P-IV, Q-III, R-I, S-II
- P-III, Q-II, R-IV, S-I
- P-IV, Q-II, R-I, S-III


Question: Which of the following sorting algorithms has the minimum running time complexity in the best and average case?

Choices:
- Insertion sort, Quick sort
- Quick sort, Quick sort
- Quick sort, Insertion sort
- Insertion sort, Insertion sort


Question: Traversal of a graph is different from tree because

Choices:
- There can be a loop in graph so we must maintain a visited flag for every vertex
- DFS of a graph uses stack, but inorder traversal of a tree is recursive
- BFS of a graph uses queue, but a time efficient BFS of a tree is recursive.
- All of the above


Question: Which of the following algorithms can be used to most efficiently determine the presence of a cycle in a given graph ?

Choices:
- Depth First Search
- Breadth First Search
- Prim\'s Minimum Spanning Tree Algorithm
- Kruskal\' Minimum Spanning Tree Algorithm


Question:
Is the following statement valid about shortest paths?
Given a graph, suppose we have calculated shortest path from a source to all other vertices.  If we modify the graph such that weights of all edges is becomes double of the original weight, then the shortest path remains same only the total weight of path changes.

Choices:
- True
- False


Question: Which of the following algorithm can be used to efficiently calculate single source shortest paths in a Directed Acyclic Graph?

Choices:
- Dijkstra
- Bellman-Ford
- Topological Sort
- Strongly Connected Component


Question:
Following statement is true or false?

If we make following changes to  Dijkstra, then it can be used to find
the longest simple path, assume that the graph is acyclic.

1) Initialize all distances as minus infinite instead of plus infinite.

2) Modify the relax condition in  Dijkstra\'s algorithm to update distance
  of an adjacent v of the currently considered vertex u only
  if "dist[u]+graph[u][v] > dist[v]". In shortest path algo,
  the sign is opposite.

Choices:
- True
- False


Question:
In a weighted graph, assume that the shortest path from a source \'s\' to a destination \'t\' is correctly calculated using a shortest path algorithm.  Is the following statement true?
If we increase weight of every edge by 1, the shortest path always remains same.

Choices:
- Yes
- No


Question: What is the time complexity of Bellman-Ford single-source shortest path algorithm on a complete graph of n vertices?

Choices:
- Θ(V2)
- Θ(V2 log v)
- Θ(V3)
- Θ(V3 log v)


Question: Suppose we run Dijkstra’s single source shortest-path algorithm on the following edge weighted directed graph with vertex P as the source. In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized? (GATE CS 2004)

Choices:
- P, Q, R, S, T, U
- P, Q, R, U, S, T
- P, Q, R, U, T, S
- P, Q, T, R, U, S


Question: In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity by

Choices:
- Dijkstra’s algorithm starting from S.
- Warshall’s algorithm
- Performing a DFS starting from S.
- Performing a BFS starting from S.


Question: Dijkstra’s single source shortest path algorithm when run from vertex a in the below graph, computes the correct shortest path distance to

Choices:
- only vertex a
- only vertices a, e, f, g, h
- only vertices a, b, c, d
- all the vertices


Question: To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:

Choices:
- Queue
- Stack
- Heap
- B-Tree


Question: Consider the directed graph shown in the figure below. There are multiple shortest paths between vertices S and T. Which one will be reported by Dijstra?s shortest path algorithm? Assume that, in any iteration, the shortest path to a vertex v is updated only when a strictly shorter path to v is discovered.

Choices:
- SDT
- SBDT
- SACDT
- SACET


Question: Which of the following is not a stable sorting algorithm in its typical implementation.

Choices:
- Insertion Sort
- Merge Sort
- Quick Sort
- Bubble Sort


Question:
Consider the following graph:

Which one of the following is NOT the sequence of edges added to the minimum spanning tree using Kruskal\'s algorithm?

Choices:
- (b,e)(e,f)(a,c)(b,c)(f,g)(c,d)
- (b,e)(e,f)(a,c)(f,g)(b,c)(c,d)
- (b,e)(a,c)(e,f)(b,c)(f,g)(c,d)
- (b,e)(e,f)(b,c)(a,c)(f,g)(c,d)


Question: Consider a weighted complete graph G on the vertex set {v1,v2 ,v} such that the weight of the edge (v,,v) is 2|i-j|. The weight of a minimum spanning tree of G is: (GATE CS 2006)

Choices:
- n — 1
- 2n — 2
- nC2
- 2


Question: Let G be an undirected connected graph with distinct edge weight. Let emax be the edge with maximum weight and emin the edge with minimum weight. Which of the following statements is false? (GATE CS 2000)

Choices:
- Every minimum spanning tree of G must contain emin
- If emax is in a minimum spanning tree, then its removal must disconnect G
- No minimum spanning tree contains emax
- G has a unique minimum spanning tree


Question:
Consider the following graph:

Which one of the following cannot be the sequence of edges added, in that order, to a minimum spanning tree using Kruskal’s algorithm?

Choices:
- (a—b),(d—f),(b—f),(d—c),(d—e)
- (a—b),(d—f),(d—c),(b—f),(d—e)
- (d—f),(a—b),(d—c),(b—f),(d—e)
- (d—f),(a—b),(b—f),(d—e),(d—c)


Question: An undirected graph G has n nodes. Its adjacency matrix is given by an n × n square matrix whose (i) diagonal elements are 0‘s and (ii) non-diagonal elements are 1‘s. which one of the following is TRUE?

Choices:
- Graph G has no minimum spanning tree (MST)
- Graph G has a unique MST of cost n-1
- Graph G has multiple distinct MSTs, each of cost n-1
- Graph G has multiple spanning trees of different costs


Question: In the graph given in above question, what is the minimum possible weight of a path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges?

Choices:
- 7
- 8
- 9
- 10


Question: Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in the matrix W below is the weight of the edge {i, j}. What is the minimum possible weight of a spanning tree T in this graph such that vertex 0 is a leaf node in the tree T? (GATE CS 2010)

Choices:
- 7
- 8
- 9
- 10


Question: The length of the path from v5 to v6 in the MST of previous question with n = 10 is

Choices:
- 11
- 25
- 31
- 41


Question: An undirected graph G(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two nodes vi , vj are connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj ) is assigned a weight i + j. A sample graph with n = 4 is shown below. What will be the cost of the minimum spanning tree (MST) of such a graph with n nodes? (GATE CS 2011)

Choices:
- 1/12(11n^2 – 5n)
- n^2 – n + 1
- 6n – 11
- 2n + 1


Question:
Quick sort is run on 2 inputs shown below to sort in ascending orderA. 1, 2, 3……n
B. n, n – 1, n – 2 …… 1
Let C1 and C2 be the number of comparisons made for A and B respectively. Then

Choices:
- C1 > C2
- C1 = C2
- C1 < C2
- Cannot say anything for arbitrary n


Question:
Quicksort is run on two inputs shown below to sort in ascending order taking the first element as pivot,(i) 1, 2, 3,......., n
(ii) n, n-1, n-2,......, 2, 1
Let C1 and C2 be the number of comparisons made for the inputs (i) and (ii) respectively. Then,

Choices:
- C1 < C2
- C1 > C2
- C1 = C2
- We cannot say anything for arbitrary n


Question: What is the best sorting algorithm to use for the elements in array are more than 1 million in general?

Choices:
- Merge sort.
- Bubble sort.
- Quick sort.
- Insertion sort.