DAA MCQ

Algorithm

The algorithm is a step-by-step process to solve any problem and is a sequence of instructions that act on some input data to produce some output in a finite number of steps. The algorithm is independent of any programming language.

Why analysis of algorithms?

  • For a given problem, there are many ways to design algorithms for it
  • Analysis of algorithms to determine which algorithm should be chosen to solve the problem.

 The complexity of algorithm on performance analysis of algorithm:

  • Time complexity:  time complexity of an algorithm is the total time required by the program to run till its completion
  •  Space complexity:  Space complexity is the total space required by an algorithm to run till its completion.

Time and space complexity depends on lots of things like hardware, OS, processes, etc.

The analysis is of two types:

  • Posteriori analysis: In Posteriori analysis, Algorithm is implemented and executed on certain fixed hardware and software. Then the algorithm is selected which takes the least amount of time to execute. Hence, the time used is given in time units like ms, ns, etc.
  • Priori analysis: In Priori analysis, The time of the algorithm is found prior to implementation. Here time is not in terms of any such time units. Instead, it represents the number of operations that are carried out while executing the algorithm.

Asymptotic notations:

  • Asymptotic notations are used to represent the complexity of an algorithm
  • With the help of asymptotic notations, we can analyze the time performance of the algorithm.

There are three types of asymptotic notations:

  • Theta notation
  •  Omega notation
  •  Big Oh Notation

Design and Analysis of Algorithms MCQ

1. 

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

2. 

What is the maximum number of swaps that can be performed in the Selection Sort algorithm?

n - 1

n

1

n - 2

3. 

What is the technique called in which it does not require extra memory for carrying out the sorting procedure?

Stable

Unstable

In-place

In-partition

4. 

What is the time complexity in decreasing the node value in a binomial heap?

O(1)

O(N)

O(logN)

O(NlogN)

5. 

What is the time complexity of the binary search algorithm?

O(n)

O(1)

O(log2n)

O(n^2)

6. 

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;
}

O(n)

O(n^2)

O(1)

O(log n)

7. 

What is the time complexity of the Sieve of Eratosthenes to check if a number is prime?

O(nlog(logn)) Precomputation, O(1) for check.

O(n) Precomputation, O(1) for the check.

O(n * logn) Precomputation, O(logn) for check.

O(n) Precomputation, O(logn) for check.

8. 

What is the time complexity to insert an element to the front of a LinkedList(head pointer given)?

O(n)

O(1)

O(logn)

O(n * logn)

9. 

What should be considered when designing an algorithm?

If this software is used correctly

In the hardware is used correctly

If there is more than one way to solve the problem

All of the above are correct

10. 

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

Bubble Sort

Merge Sort

Counting Sort

Heap Sort

11. 

When a pop() operation is called on an empty queue, what is the condition called?

Overflow

Underflow

Syntax Error

Garbage Value

12. 

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

Z Algorithm

Rabin Karp Algorithm

KMP Algorithm

All of the above

13. 

What is the best time complexity we can achieve to precompute all-pairs shortest paths in a weighted graph?

O(n^3)

O(n^2)

O(n)

O(n^4)

14. 

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

Sentence Ordering

Course Scheduling

OS Deadlock Detection

All of the above

15. 

Which of the following data structure is used to perform recursion?

Linked list

Array

Queue

Stack

16. 

Which of the following functions provides the maximum asymptotic complexity?

f1(n) = n^(3/2)

f2(n) = n^(logn)

f3(n) = nlogn

f4(n) = 2^n.

17. 

Which of the following is a Divide and Conquer algorithm?

Bubble Sort

Selection Sort

Heap Sort

Merge Sort

18. 

Which of the following is incorrect? Algorithms can be represented:

As programs

As flow charts

As syntax

As pseudo-codes

19. 

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

Vertex Cover Problem

0/1 Knapsack Problem

Maximal Independent Set Problem

Travelling Salesman Problem

20. 

Which of the following is used for solving the N Queens Problem?

Greedy algorithm

Dynamic programming

Backtracking

Sorting

21. 

Which of the following sorting algorithms provide the best time complexity in the worst-case scenario?

Merge Sort

Quick Sort

Bubble Sort

Selection Sort

22. 

Which of the following statements is true about AVL Trees?

The difference between the heights of left and right nodes cannot be more than 1.

The height of an AVL Tree always remains of the order of O(logn)

AVL Trees are a type of self-balancing Binary Search Trees.

All of the above.

23. 

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

O(n)

O(n * logn)

O(1)

O(logn)

24. 

In what time complexity can we find the diameter of a binary tree optimally?

O(V + E)

O(V)

O(E)

O(V * logE)

25. 

An algorithm is __________?

A problem

A procedure for solving a problem

A real-life mathematical problem

None of the above

26. 

Another name of the fractional knapsack is?

Non-continuous knapsack problem

Divisible knapsack problem

0/1 knapsack problem

Continuous Knapsack Problem

27. 

Dijkstra’s algorithm is used to solve __________  problems?

Network lock

Single source shortest path

All pair shortest path

Sorting

28. 

Hamiltonian path problem is _________?

NP problem

P class problem

NP-complete problem

N class problem

29. 

Heap is a _____________?

Tree structure

Complete binary tree

Binary tree

None of the above

30. 

Identify the approach followed in Floyd Warshall’s algorithm?

Linear programming

Dynamic Programming

Greedy Technique

Backtracking

31. 

Identify the best case time complexity of selection sort?

O(nlogn)

O(n^2)

O(n)

O(1)

32. 

Identify the function of the stack that returns the top data element of the stack?

pop()

peek()

push()

findTop()

33. 

Identify the slowest sorting technique among the following?

Merge Sort

Quick Sort

Bubble Sort

Selection Sort

34. 

Identify the sorting technique which compares adjacent elements in a list and switches whenever necessary?

Merge Sort

Quick Sort

Bubble Sort

Selection Sort

35. 

In a graph of n nodes and n edges, how many cycles will be present?

Exactly 1

At most 1

At most 2

Depending on the graph

36. 

Among the following options which is the best sorting algorithm when the list is already sorted?

Merge Sort

Insertion Sort

Bubble Sort

Selection Sort

37. 

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

38. 

Representation of data structure in memory is known as?

Storage structure

File structure

Recursive

Abstract Data Type

39. 

Select the correct recurrence relation for Tower of Hanoi?

T(N) = 2T(N-1)+1

T(N) = 2T(N/2)+1

T(N) = 2T(N-1)+N

T(N) = 2T(N-2)+2

40. 

The Bellmann Ford Algorithm returns __________  value?

String

Boolean

Double

Integer

41. 

The time complexity for travel Singh all nodes in a binary search tree with n nodes and printing them in order is?

O(n)

O(1)

O(nlog2n)

O(n^2)

42. 

The time complexity to find the longest common subsequence of two strings of length M and N is?

O(N)

O(M * N)

O(M)

O(log N)

43. 

The worst-case time complexity of Quicksort is?

O(n)

O(1)

O(log2n)

O(n^2)

44. 

The worst-case time complexity of Selection Exchange Sort is?

O(n)

O(1)

O(log2n)

O(n^2)

45. 

To main measures of the efficiency of an algorithm are?

Time and space complexity

Data and space

Processor and memory

Complexity and capacity

46. 

What is the best case time complexity of the binary search algorithm?

O(1)

O(n)

O(log2n)

O(n^2)