Computer
Computer
Computer
if(i % 2 == 0) {
sum += a[i];
}
}
cout << sum << endl;
}
A. 5
B. 15
C. 9
D. 6
11. Which of the following is the advantage of the array data structure?
A. Elements of mixed data types can be stored.
B. Easier to access the elements in an array
C. Index of the first element starts from 1.
D. Elements of an array cannot be sorted
15. What is the time complexity of the following code snippet in C++?
void solve() {
string s = "scaler";
int n = s.size();
for(int i = 0; i < n; i++) {
s = s + s[i];
}
cout << s << endl;
}
A. O(n)
B. O(n^2)
C. O(1)
D. O(log n)
17. Which of the following data structures finds its use in recursion?
A. Stack
B. Arrays
C. LinkedList
5
D. Queues
18. Which of the following data structures allow insertion and deletion
from both ends?
A. Stack
B. Deque
C. Queue
D. Strings
20. Which of the following sorting algorithms provide the best time
complexity in the worst-case scenario?
A. Merge Sort
B. Quick Sort
C. Bubble Sort
D. Selection Sort
6
21. What is the maximum number of swaps that can be performed in the
Selection Sort algorithm?
A. n - 1
B. n
C. 1
D. n - 2
23. What will be the best sorting algorithm, given that the array elements
are small (<= 1e6)?
A. Bubble Sort
B. Merge Sort
C. Counting Sort
D. Heap Sort
26. Which of the following algorithms are used for string and pattern
matching problems?
A. Z Algorithm
B. Rabin Karp Algorithm
C. KMP Algorithm
7
28. Which of the following algorithms are useful for processing queries on
trees?
A. Centroid Decomposition.
B. Heavy Light Decomposition.
C. Both (A) and (B).
D. Neither (A) nor (B).
29. 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;
}
A. 1 2 3 4 5
B. 5 4 3 2 1
C. 1 3 5 2 4
D. 2 4 1 3 5
C. O(log2n)
D. O(n^2)
32. Kruskal’s Algorithm for finding the Minimum Spanning Tree of a graph
is a kind of a?
A. DP Problem.
B. Greedy Algorithm.
C. Adhoc Problem.
D. None of the above.
34. Maps in C++ are implemented using which of the following data
structures?
A. Red-Black Trees.
B. Binary Search Trees.
9
C. AVL Trees.
D. Hash Tables.
38. What is the best case time complexity of the binary search algorithm?
A. O(1)
B. O(n)
C. O(log2n)
D. O(n^2)
44. What is the maximum number of children a node can have in an n-ary
tree?
A. 2
B. 0
C. 1
D. n
45. Worst case time complexity to access an element in a BST can be?
A. O(n)
B. O(n * logn)
C. O(1)
D. O(logn)
47. In what time complexity can we find the diameter of a binary tree
optimally?
A. O(V + E)
B. O(V)
C. O(E)
D. O(V * logE)
49. 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;
}
A. Calculates the number of edges in an undirected graph.
B. Calculates the number of nodes in a given graph.
C. Calculates the sum of degrees of all nodes in a given graph.
D. None of the above.
50. In a graph of n nodes and n edges, how many cycles will be present?
A. Exactly 1
B. At most 1
C. At most 2
D. Depends on the graph
51. A node in a tree, such that removing it splits the tree into forests, with
size of each connected component being not greater than n / 2 is called?
A. Center
B. Diameter
C. Centroid
D. Path
dp[x] = dp[node] + 1;
dfs(x, edges, vis, dp);
}
}
}
A. Stores depths of all the nodes in a given tree, with respect to some root
node.
B. Counts the number of nodes in a given tree.
C. Finds the diameter of a tree.
D. Checks if all the nodes are reachable in a given tree.
53. Which of the following algorithms are used to find the shortest path
from a source node to all other nodes in a weighted graph?
A. BFS.
B. Djikstra’s Algorithm.
C. Prims Algorithm.
D. Kruskal’s Algorithm.
54. What is the best time complexity we can achieve to precompute all-
pairs shortest paths in a weighted graph?
A. O(n^3)
B. O(n^2)
C. O(n)
D. O(n^4)
55. Which data structure is mainly used for implementing the recursive
algorithm?
A. Queue
B. Stack
C. Array
D. List
13
a) Binary search
b) Interpolation search
c) Jump search
d) Sequential search
a) Quick sort
b) Merge sort
c) Bubble sort
d) Heap sort
a) Random access
b) Fixed size
14
c) Memory efficiency
d) Ease of insertion and deletion
a) AVL tree
b) B-tree
c) Binary tree
d) Heap tree
a) Dictionary
b) Spell checker
c) Cache
d) Binary search tree
a) Depth-first search
b) Breadth-first search
c) Dijkstra’s algorithm
d) Bellman-Ford algorithm
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Needleman-Wunsch algorithm
a) Stack
b) Queue
c) Heap
d) Linked list.
a) P
b) NP
c) NP-complete
d) E
a) Merge sort
b) Quick sort
c) Binary search
d) Bubble sort
a) Stack
b) Queue
c) Heap
d) Hash table
15. Which of the following is not a basic operation of a binary search tree?
a) Insert
b) Delete
c) Search
d) Traverse
16
a) Bellman-Ford algorithm
b) Dijkstra’s algorithm
c) Floyd-Warshall algorithm
d) A* algorithm
a) Stack
b) Queue
c) Heap
d) Linked list
a) Breadth-first search
b) Depth-first search
c) Dijkstra’s algorithm
d) Prim’s algorithm
20. Which data structure would be best suited for implementing a LIFO
(Last In First Out) behavior?
a) Queue
b) Stack
c) Heap
d) Tree
17
a) Quick sort
b) Heap sort
c) Merge sort
d) Selection sort
a) Queue
b) Stack
c) Heap
d) Linked list
a) Binary search
b) Linear search
c) Hashing
d) Bubble sort
24. Which of the following algorithms can be used to find the shortest path
between two nodes in a weighted graph?
a) Breadth-first search
b) Depth-first search
c) Dijkstra’s algorithm
d) Prim’s algorithm
a) Linked list
b) Queue
18
c) Stack
d) Array
a) O(1)
b) O(log n)
c) O(n^2)
d) O(n!)
a) Queue
b) Stack
c) Linked list
d) Array
28. Which of the following algorithms is used to find the strongly connected
components in a directed graph?
a) Breadth-first search
b) Depth-first search
c) Dijkstra’s algorithm
d) Kruskal’s algorithm
a) Linked list
b) Heap
c) Tree
d) Hash table
19
30. Which of the following algorithms is used to find the shortest path
between two nodes in a graph?
a) Breadth-first search
b) Depth-first search
c) Dijkstra’s algorithm
d) Prim’s algorithm
a) Linked list
b) Stack
c) Hash table
d) Binary tree
a) Quick sort
b) Merge sort
c) Heap sort
d) Bubble sort
a) Adjacency list
b) Adjacency matrix
c) Hash table
d) Edge list
a) Breadth-first search
b) Depth-first search
20
c) Dijkstra’s algorithm
d) Prim’s algorithm
a) Linked list
b) Array
c) Stack
d) Queue
36. Which of the following algorithms is used to find the maximum flow in
a network?
a) Breadth-first search
b) Depth-first search
c) Dijkstra’s algorithm
d) Ford-Fulkerson algorithm
a) Breadth-first search
b) Depth-first search
c) Hill climbing
d) Binary search
a) Linked list
b) Stack
c) Heap
d) Binary tree
21
a) Quick sort
b) Merge sort
c) Kadane’s algorithm
d) Binary search
a) Bubble sort
b) Insertion sort
c) Selection sort
d) Combination sort
41. Which of the following algorithms is used to find the shortest path in a
graph with non-negative edge weights?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Kruskal’s algorithm
a) Quick sort
b) Merge sort
c) Selection sort
d) Bubble sort
a) Adjacency matrix
b) Adjacency list
22
c) Hash table
d) Edge list
44. Which of the following algorithms is used to find the maximum value in
an array of integers?
a) Bubble sort
b) Merge sort
c) Quick sort
d) Linear search
a) Linked list
b) Array
c) Heap
d) Binary tree
a) Debugging
b) Unit testing
c) System testing
d) Regression testing
a) Unit testing
b) Integration testing
23
c) Acceptance testing
d) Maintenance testing
a) Manual testing
b) Automated testing
c) White box testing
d) Parallel testing
a) Performance testing
b) Security testing
c) Integration testing
d) Unit testing
a) Equivalence partitioning
b) Boundary value analysis
c) State transition testing
d) Structural testing
a) Regression testing
b) Acceptance testing
c) Integration testing
d) Usability testing
a) Pair programming
b) Code review
c) Code coverage analysis
d) Continuous integration
a) Code review
b) Test case design
c) Traceability analysis
d) Use case analysis
a) Syntax error
b) Logical error
c) Semantic error
d) All of the above
A – Queue
B - Stack
C - Hash Table
C - Recursion
26
A - true
B – false
A - Merge Sort
B - Insertion Sort
C - Quick Sort
D - Heap Sort
A-3
B-4
C-5
D-6
A - Ο(1)
B - Ο(n)
C - Ο(log n)
D - Ο(log log n)
Q 8 - Heap is an example of
B - spanning tree
C - sparse tree
A - Ο(1)
B - Ο(log n)
C - Ο(n)
D - Ο(n2)
A - linear search
B - binary search
C - merge sort
D - quick sort