PYTHON DATA STRUCTURE QUIZ DESCRIPTION

Which of the following data structures is preferred in the implementation of a database system?

  •  B-Tree
     

  •  Binary Search Tree

  •  AVL Tree

  •  B+- Tree

What will be the output of the following code snippet?
int search(int l, int r, int target, vector<int> &a) {
   int mid = (l + r) / 2;
   if(a[mid] == target) {
       return mid;
   }
   else if(a[mid] < target) {
       return search(mid + 1, r, target, a);
   }
   else {
       return search(0, mid - 1, target, a);
   }
}
void solve() {
   vector<int> a = {1, 2, 3, 4, 5};
   cout << search(0, 4, 4, a) << endl;
}

  • 3

  • 4

  • 0

  • 2

Which one of these is not a Built-in Data Structure of python?

  • List
     

  •  Tuple

  •  Structure

  •  Set
     

Consider we have a function, getLCA(), which returns us the Lowest Common Ancestor between 2 nodes of a tree. Using this getLCA() function, how can we calculate the distance between 2 nodes, given that distance from the root, to each node is calculated?
 

  • dist(u) + dist(v) - 2 * dist(getLCA(u, v))
     

  • dist(u) + dist(v) + 2 * dist(getLCA(u, v))

  • dist(u) + dist(v)

  • dist(u) + dist(v) - dist(getLCA(u, v))

What is the most important criteria that must be met before being inserted into a linked queue?
 

  • Underflow
     

  • Overflow

  • Front value

  • Rear value
     

What does the following code snippet do?
void dfs(int node, vector<vector<int>> &edges, vector<bool> &vis, vector<int> &dp) {
   vis[node] = true;
   for(auto x: edges[node]) {
       if(!vis[x]) {
           dp[x] = dp[node] + 1;
           dfs(x, edges, vis, dp);
       }
   }
}

  • Stores depths of all the nodes in a given tree, with respect to some root node.
     

  • Counts the number of nodes in a given tree.

  • Finds the diameter of a tree.

  • Checks if all the nodes are reachable in a given tree.

Which data structure is mainly used for implementing the recursive algorithm?

  • Queue
     

  • Stack

  • Array

  • List

Which of the following are applications of Topological Sort of a graph?

  • Sentence Ordering.
     

  • Course Scheduling.

  • OS Deadlock Detection.

  • All of the above.
     

What is the time complexity of the binary search algorithm?

  • O(n)
     

  • O(1)

  • O(log2n)

  • O(n^2)

Which of the following algorithms are useful for processing queries on trees?
 

  • Centroid Decomposition.
     

  • Heavy Light Decomposition.

  • Both (A) and (B).

  • Neither (A) nor (B).

How is an array initialized in C language?

  • int a[3] = {1, 2, 3};
     


  • int a = {1, 2, 3};
     


  • int a[] = new int[3]
     


  • int a(3) = [1, 2, 3];

Kruskal’s Algorithm for finding the Minimum Spanning Tree of a graph is a kind of a?

  • DP Problem.
     

  • Greedy Algorithm.

  • Adhoc Problem.

  • None of the above.

Which of the following code snippet is used to convert decimal to binary numbers?
 

  • public void convertBinary(int num)
    {
    int bin[] = new int[50];
    int index = 0;
    while(num > 0)
    {
    bin[index++] = num%2;
    num = num/2;
    }
    for(int i = index-1;i >= 0;i--)
    {
    Syst

  • public void convertBinary(int num)
    {
    int bin[] = new int[50];
    int index = 0;
    while(num > 0)
    {
    bin[++index] = num/2;
    num = num%2;
    }
    for(int i = index-1;i >= 0;i--)
    {
    Syst

  • public void convertBinary(int num)
    {
    int bin[] = new int[50];
    int index = 0;
    while(num > 0)
    {
    bin[index++] = num/2;
    num = num%2;
    }
    for(int i = index-1;i >= 0;i--)
    {
    Syst

  • public void convertBinary(int num)
    {
    int bin[] = new int[50];
    int index = 0;
    while(num > 0)
    {
    bin[++index] = num%2;
    num = num/2;
    }
    for(int i = index-1;i >= 0;i--)
    {
    Syst

which feature does not match with python

  • open source
     

  • interpreted

  •    compiled

  •  high level
     

What will be the best sorting algorithm, given that the array elements are small (<= 1e6)?

  • Bubble Sort
     

  • Merge Sort

  • Counting Sort

  • Heap Sort
     

Python is successor of which language?

  • XYZ
     

  •  Java

  •    C++

  •  ABC
     

Worst case time complexity to access an element in a BST can be?

  • O(n)
     

  • O(n * logn)

  • O(1)

  • O(logn)

What will be the output of the following code snippet?
void solve() {
   int n = 24;
   int l = 0, r = 100, ans = n;
   while(l <= r) {
       int mid = (l + r) / 2;
       if(mid * mid <= n) {
           ans = mid;
           l = mid + 1;
       }
       else {
           r = mid - 1;
       }
   }
   cout << ans << endl;
}

  • 5

  • 4

  • 6

  • 3

What is the extentions for the python file?

  • python
     

  •  py

  •    pi

  •    pi3

Which of the following is a non-linear data structure?

  •  Array
     


  •  Linked List
     

  •  
     Queue
     


  •  Tree

What does the following code snippet calculate (edges represent the adjacency list representation of a graph)?
void solve(vector<vector<int>> edges) {
   int count = 0;
   for(auto x: edges) {
       for(auto y: x) {
           count += 1;
       }
   }
   cout << count / 2 << endl;
}

  • Calculates the number of edges in an undirected graph.
     

  • Calculates the number of nodes in a given graph.

  • Calculates the sum of degrees of all nodes in a given graph.

  • None of the above.

Dijkstra’s Algorithm cannot be applied on which of the following?

  •  Directed and weighted graphs
     

  •  Graphs having negative weight function

  •  Unweighted graphs

  •  Undirected and unweighted graphs

Which of the following algorithms are used to find the shortest path from a source node to all other nodes in a weighted graph?
BFS.

  • Djikstra’s Algorithm.
     

  • Prims Algorithm.

  • Kruskal’s Algorithm.

In circular queue, the value of REAR would be?

  •  REAR = REAR + 1
     

  •  REAR = (REAR + 1) % (QUEUE_SIZE+1)

  •  REAR = (REAR + 1) % (QUEUE_SIZE)

  •  REAR = (REAR - 1) % (QUEUE_SIZE-1)

What is the maximum number of children a node can have in an n-ary tree?
 

  • 2

  • 0

  • 1

  • n

 

What will the output of the following code snippet be?

void solve() {
   vector<int> a = {1, 2, 3, 4, 5};
   sort(a.begin(), a.end(), [&](const int &x, const int &y) {
       return x % 2 < y % 2;
   });
   for(int x: a) {
       cout << x << " ";
   }
   cout << endl;
}

  • 1 2 3 4 5
     

  • 5 4 3 2 1

  • 1 3 5 2 4

  • 2 4 1 3 5

What will be the final elements on the stack if the following sequence of operations are executed?
Push(a,s);
Push(b,s);
Pop(s);
Push(c,s);
where a, b, c are the data elements and s is the stack.

  • abc

  • ac

  • acb

  • a

In what traversal we process all of a vertex’s descendants before we move to an adjacent vertex?

  •  BFS
     


  •  DFS
     


  •  Level Order
     


  •  Width first

Which of the following algorithms are used for string and pattern matching problems?
 

  • Z Algorithm
     

  • Rabin Karp Algorithm

  • KMP Algorithm

  • All of the above
     

What will be the output of the following code snippet?
void solve() {
   string s = "00000001111111";
   int l = 0, r = s.size() - 1, ans = -1;
   while(l <= r) {
       int mid = (l + r) / 2;
       if(s[mid] == '1') {
           ans = mid;
           r = mid - 1;
       }
       else {
           l = mid + 1;
       }
   }
   cout << ans << endl;
}

  • 6

  • 7

  • 0

  • 1