0% found this document useful (0 votes)
20 views

Design & Analyze of Algorithm

The document contains a series of multiple-choice questions (MCQs) related to algorithms, data structures, and their complexities. Topics include definitions of algorithms, time complexities of various functions and algorithms, characteristics of recursive functions, greedy algorithms, dynamic programming problems, and NP-complete problems. Each question provides four options for answers, testing knowledge in computer science fundamentals.

Uploaded by

Abubakar Siddiq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Design & Analyze of Algorithm

The document contains a series of multiple-choice questions (MCQs) related to algorithms, data structures, and their complexities. Topics include definitions of algorithms, time complexities of various functions and algorithms, characteristics of recursive functions, greedy algorithms, dynamic programming problems, and NP-complete problems. Each question provides four options for answers, testing knowledge in computer science fundamentals.

Uploaded by

Abubakar Siddiq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MCQS

1. What is an algorithm?
a) A step-by-step procedure to solve a problem
b) A flowchart
c) A programming language
d) A data structure

2.What is the time complexity of the following function: f(n) = 2n^2


+ 3n + 1?
a) O(n)
b) O(n^2)
c) O(n^3)
d) O(log n)

3. Which of the following is a recursive function?


a) int factorial(int n) { return n * factorial(n-1); }
b) int factorial(int n) { int result = 1; for (int i = 1; i <= n; i++) result
*= i; return result; }
c) Both a and b
d) Neither a nor b

4. Which algorithm uses the divide-and-conquer approach?


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

5. What is the time complexity of quicksort in the worst case?


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

6. What is the time complexity of searching for an element in a


balanced binary search tree?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)

7. What is the time complexity of inserting an element into a max


heap?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)

8.What is the time complexity of searching for an element in a hash


table with separate chaining?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(1) (on average)

9. Which algorithm is a greedy algorithm?


a) Dijkstra's algorithm
b) Bellman-Ford algorithm
c) Kruskal's algorithm
d) All of the above

10. Which problem can be solved using dynamic programming?


a) The knapsack problem
b) The traveling salesman problem
c) The shortest path problem
d) All of the above

11. What is the time complexity of Dijkstra's algorithm?


a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
12. Which algorithm is used to find the shortest path in a graph
with negative edge weights?
a) Dijkstra's algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) A* search

13. What is the Ford-Fulkerson algorithm used for?


a) Finding the shortest path in a graph
b) Solving the maximum flow problem
c) Sorting a list of elements
d) Finding the minimum spanning tree of a graph

14. What is the time complexity of the Union-Find data structure


with path compression and weighted union?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(α(n)) (inverse Ackermann function)

15. What is the time complexity of multiplying two n x n matrices?


a) O(n)
b) O(n log n)
c) O(n^2)
d) O(n^3)

16. Which string matching algorithm uses a prefix table?


a) Naive string matching
b) Rabin-Karp algorithm
c) KMP algorithm
d) Boyer-Moore algorithm

17. Which of the following is an NP-complete problem?


a) Traveling salesman problem
b) Knapsack problem
c) Vertex cover problem
d) All of the above

18. What is the approximation ratio of the greedy algorithm for the
vertex cover problem?
a) 2
b) 3
c) 4
d) 5

19. Which of the following is not an NP-complete problem?


a) Satisfiability problem (SAT)
b) Traveling salesman problem (TSP)
c) Knapsack problem
d) Linear programming problem

20. What is the approximation ratio of the greedy algorithm for the
set covering problem?
a) 2
b) 3
c) 4
d) It depends on the specific instance of the problem.

You might also like