Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Computer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

1

1. How is an array initialized in C language?


A. int a[3] = {1, 2, 3};
B. int a = {1, 2, 3};
C. int a[] = new int[3]
D. int a(3) = [1, 2, 3];

2. Which of the following is a linear data structure?


A. Array
B. AVL Trees
C. Binary Trees
D. Graphs

3. How is the 2nd element in an array accessed based on pointer


notation?
A. *a + 2
B. *(a + 2)
C. *(*a + 2)
D. &(a + 2)

4. Which of the following is not the type of queue?


A. Priority queue
B. Single-ended queue
C. Circular queue
D. Ordinary queue

5. From following which is not the operation of data structure?


A. Operations that manipulate data in some way
B. Operations that perform a computation
C. Operations that check for syntax errors
D. Operations that monitor an object for the occurrence of a controlling event

6. What will be the output of the following code snippet?


void solve() {
int a[] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
2

if(i % 2 == 0) {
sum += a[i];
}
}
cout << sum << endl;
}
A. 5
B. 15
C. 9
D. 6

7. What will the output of the following code snippet?


void solve() {
int a[] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
sum += *(a + i);
}
else {
sum -= *(a + i);
}
}
cout << sum << endl;
}
A. 2
B. 15
C. Syntax Error
D. 3

8. What is the disadvantage of array data structure?


A. The amount of memory to be allocated should be known beforehand.
B. Elements of an array can be accessed in constant time.
C. Elements are stored in contiguous memory blocks.
D. Multiple other data structures can be implemented using arrays.
3

9. How are String represented in memory in C?


A. An array of characters.
B. The object of some class.
C. Same as other primitive data types.
D. LinkedList of characters.

10. What is the output of the following code snippet?


void solve() {
stack<int> s;
s.push(1);
s.push(2);
s.push(3);
for(int i = 1; i <= 3; i++) {
cout << s.top() << “ “;
s.pop();
}
}
A. 3 2 1
B. 1 2 3
C. 3
D. 1

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

12. What function is used to append a character at the back of a string in


C++?
A. push_back()
B. append()
C. push()
D. insert()

13. Which one of the following is an application of queue data structure


4

A. When a resource is shared among multiple consumers.


B. When data is transferred asynchronously
C. Load Balancing
D. All of the above

14. When a pop() operation is called on an empty queue, what is the


condition called?
A. Overflow
B. Underflow
C. Syntax Error
D. Garbage Value

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)

16. Which of the following data structures can be used to implement


queues?
A. Stack
B. Arrays
C. LinkedList
D. All of the Above

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

19. What will be the output of the following code snippet?


void solve() {
deque<int> dq;
for(int i = 1; i <= 5; i++) {
if(i % 2 == 0) {
dq.push_back(i);
}
else {
dq.push_front(i);
}
}
for(auto x: dq) {
cout << x << " ";
}
cout << endl;
}
A. 1 2 3 4 5
B. 5 4 3 2 1
C. 1 3 5 2 4
D. 5 3 1 2 4

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

22. Which of the following is a Divide and Conquer algorithm?


A. Bubble Sort
B. Selection Sort
C. Heap Sort
D. Merge Sort

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

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


A. Sentence Ordering.
B. Course Scheduling.
C. OS Deadlock Detection.
D. All of the above.

25. Which of the following is known to be not an NP-Hard Problem?


A. Vertex Cover Problem.
B. 0/1 Knapsack Problem.
C. Maximal Independent Set Problem.
D. Travelling Salesman Problem.

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

D. All of the above

27. 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?
A. dist(u) + dist(v) - 2 * dist(getLCA(u, v))
B. dist(u) + dist(v) + 2 * dist(getLCA(u, v))
C. dist(u) + dist(v)
D. dist(u) + dist(v) - dist(getLCA(u, v))

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

31. What is the time complexity of the binary search algorithm?


A. O(n)
B. O(1)
8

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.

33. 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;
}
A. 6
B. 7
C. 0
D. 1

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.

36. What is the time complexity of the Sieve of Eratosthenes to check if a


number is prime?
A. O(nlog(logn)) Precomputation, O(1) for check.
B. O(n) Precomputation, O(1) for the check.
C. O(n * logn) Precomputation, O(logn) for check.
D. O(n) Precomputation, O(logn) for check.

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)

39. What is the time complexity to insert an element to the front of a


LinkedList(head pointer given)?
A. O(n)
B. O(1)
C. O(logn)
D. O(n * logn)

40. What is the time complexity to insert an element to the rear of a


LinkedList(head pointer given)?
A. O(n)
B. O(1)
C. O(logn)
D. O(n * logn)

42. Which of the following can be done with LinkedList?


A. Implementation of Stacks and Queues
B. Implementation of Binary Trees
C. Implementation of Data Structures that can simulate Dynamic Arrays
D. All of the above

43. What is the information, which a LinkedList’s Node must store?


10

A. The address of the next node if it exists


B. The value of the current node
C. Both (A) and (B)
D. None of the above

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)

46. Which of the following represents the Postorder Traversal of a Binary


Tree?
A. Left -> Right -> Root
B. Left -> Root -> Right
C. Right -> Left -> Root
D. Right -> Root -> Left

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)

48. Which of the following statements is true about AVL Trees?


A. The difference between the heights of left and right nodes cannot be more
than 1.
B. The height of an AVL Tree always remains of the order of O(logn)
C. AVL Trees are a type of self-balancing Binary Search Trees.
11

D. All of the above.

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

52. 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]) {
12

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

Top 60 Data Structures and Algorithms MCQs

1. Which of the following data structures is not linear? a) Array


b) Linked List
c) Stack
d) Tree

2. Which of the following is not an application of a stack? a) Function


call stack
b) Browser back button
c) Undo/Redo operation
d) Binary search

3. Which of the following is not a basic operation of a queue? a) Enqueue


b) Dequeue
c) Peek
d) Traverse

4. Which of the following is an example of a linear search algorithm?

a) Binary search
b) Interpolation search
c) Jump search
d) Sequential search

5. Which of the following is not a sorting algorithm with a worst-case time


complexity of O(n log n)?

a) Quick sort
b) Merge sort
c) Bubble sort
d) Heap sort

6. Which of the following is a disadvantage of using linked lists over arrays?

a) Random access
b) Fixed size
14

c) Memory efficiency
d) Ease of insertion and deletion

7. Which of the following is a type of tree that maintains a heap property?

a) AVL tree
b) B-tree
c) Binary tree
d) Heap tree

8. Which of the following is not a common application of a hash table?

a) Dictionary
b) Spell checker
c) Cache
d) Binary search tree

9. Which of the following is a graph traversal algorithm that visits nodes in


breadth-first order?

a) Depth-first search
b) Breadth-first search
c) Dijkstra’s algorithm
d) Bellman-Ford algorithm

10. Which of the following is a dynamic programming algorithm for solving


the longest common subsequence problem?

a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Needleman-Wunsch algorithm

11. Which of the following is a data structure that implements a priority


queue?
15

a) Stack
b) Queue
c) Heap
d) Linked list.

12. Which of the following is not a complexity class used to classify


algorithms?

a) P
b) NP
c) NP-complete
d) E

13. Which of the following is not an example of a divide-and-conquer


algorithm?

a) Merge sort
b) Quick sort
c) Binary search
d) Bubble sort

14. Which of the following is a data structure that implements a set?

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

16. Which of the following is not an example of a greedy algorithm?


a) Dijkstra’s algorithm
b) Kruskal’s algorithm
c) Prim’s algorithm
d) Depth-first search

17. Which of the following is not a dynamic programming algorithm for


solving the shortest path problem?

a) Bellman-Ford algorithm
b) Dijkstra’s algorithm
c) Floyd-Warshall algorithm
d) A* algorithm

18. Which of the following is a data structure that implements a deque?

a) Stack
b) Queue
c) Heap
d) Linked list

19. Which of the following is not a graph traversal algorithm?

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

21. Which of the following sorting algorithms is considered stable?

a) Quick sort
b) Heap sort
c) Merge sort
d) Selection sort

22. Which of the following data structures can be used to implement a


priority queue?

a) Queue
b) Stack
c) Heap
d) Linked list

23. Which of the following is not a searching algorithm?

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

25. Which of the following data structures is used to implement a hash


table?

a) Linked list
b) Queue
18

c) Stack
d) Array

26. Which of the following is not a common complexity class used to


analyze algorithms?

a) O(1)
b) O(log n)
c) O(n^2)
d) O(n!)

27. Which of the following data structures can be used to implement a


binary search?

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

29. Which of the following is a common data structure used for


implementing a stack?

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

31. Which of the following data structures is used to implement a queue?

a) Linked list
b) Stack
c) Hash table
d) Binary tree

32. Which of the following sorting algorithms has a worst-case time


complexity of O(n^2)?

a) Quick sort
b) Merge sort
c) Heap sort
d) Bubble sort

33. Which of the following is not a common data structure used to


represent a graph?

a) Adjacency list
b) Adjacency matrix
c) Hash table
d) Edge list

34. Which of the following algorithms is used to find the minimum


spanning tree of a weighted undirected graph?

a) Breadth-first search
b) Depth-first search
20

c) Dijkstra’s algorithm
d) Prim’s algorithm

35. Which of the following data structures is used to implement a binary


search?

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

37. Which of the following is not a common search algorithm used in


artificial intelligence?

a) Breadth-first search
b) Depth-first search
c) Hill climbing
d) Binary search

38. Which of the following data structures is used to implement a priority


queue?

a) Linked list
b) Stack
c) Heap
d) Binary tree
21

39. Which of the following algorithms is used to find the maximum


subarray sum in an array of integers?

a) Quick sort
b) Merge sort
c) Kadane’s algorithm
d) Binary search

40. Which of the following is not a common sorting algorithm?

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

42. Which of the following algorithms is used to sort a linked list?

a) Quick sort
b) Merge sort
c) Selection sort
d) Bubble sort

43. Which of the following is not a common data structure used to


implement a graph?

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

45. Which of the following data structures is used to implement a stack?

a) Linked list
b) Array
c) Heap
d) Binary tree

46. Which of the following is not a software testing technique?

a) Boundary value analysis


b) Equivalence partitioning
c) Code optimization
d) Decision table testing

47. The process of finding and fixing defects in software is called:

a) Debugging
b) Unit testing
c) System testing
d) Regression testing

48. Which of the following is not a level of software testing?

a) Unit testing
b) Integration testing
23

c) Acceptance testing
d) Maintenance testing

49. Which of the following is not a type of software testing?

a) Manual testing
b) Automated testing
c) White box testing
d) Parallel testing

50. Which of the following is a functional testing technique?

a) Boundary value analysis


b) Regression testing
c) Load testing
d) Usability testing

51. Which of the following is a non-functional testing technique?

a) Performance testing
b) Security testing
c) Integration testing
d) Unit testing

52. Which of the following is not a black box testing technique?

a) Equivalence partitioning
b) Boundary value analysis
c) State transition testing
d) Structural testing

53. Which of the following is not a goal of software testing?

a) To find defects or bugs in the software


b) To improve the quality of the software
24

c) To ensure that the software meets its requirements


d) To eliminate the need for maintenance and support

54. Which of the following is a white box testing technique?

a) Boundary value analysis


b) Equivalence partitioning
c) Control flow testing
d) Decision table testing

55. Which of the following is a testing technique that involves using


previously developed test cases to test new versions of the software?

a) Regression testing
b) Acceptance testing
c) Integration testing
d) Usability testing

56. Which of the following is a non-functional requirement?

a) The software shall be able to add two numbers


b) The software shall be user-friendly
c) The software shall be compatible with Windows and Mac operating systems
d) The software shall be able to handle 1000 concurrent users

57. Which of the following is a technique for measuring software quality?

a) Pair programming
b) Code review
c) Code coverage analysis
d) Continuous integration

58. Which of the following is a technique for detecting defects in software


requirements?
25

a) Code review
b) Test case design
c) Traceability analysis
d) Use case analysis

59. Which of the following is a type of software defect?

a) Syntax error
b) Logical error
c) Semantic error
d) All of the above

60. Which of the following is a black box testing technique?

a) Boundary value analysis


b) Statement coverage
c) Branch coverage
d) Path testing

Q 1 - Which of the following usees FIFO method

A – Queue

B - Stack

C - Hash Table

D - Binary Search Tree

Q 2 - Stack is used for

A - CPU Resource Allocation

B - Breadth First Traversal

C - Recursion
26

D - None of the above

Q 3 - A linked-list is a dynamic structure

A - true

B – false

Q 4 - If the array is already sorted, which of these algorithms will exhibit


the best performance

A - Merge Sort

B - Insertion Sort

C - Quick Sort

D - Heap Sort

Q 5 - Graph traversal is different from a tree traversal, because

A - trees are not connected.

B - graphs may have loops.

C - trees have root.

D - None is true as tree is a subset of graph.

Q 6 - The number of binary trees with 3 nodes which when traversed in


post order gives the sequence A,B,C is ?

A-3

B-4

C-5

D-6

Q 7 - Linked list search complexity is


27

A - Ο(1)

B - Ο(n)

C - Ο(log n)

D - Ο(log log n)

Q 8 - Heap is an example of

A - complete binary tree

B - spanning tree

C - sparse tree

D - binary search tree

Q 9 - Re-balancing of AVL tree costs

A - Ο(1)

B - Ο(log n)

C - Ο(n)

D - Ο(n2)

Q 10 - Which of the following algorithm does not divide the list −

A - linear search

B - binary search

C - merge sort

D - quick sort

You might also like