Top MCQs on Greedy Algorithms with Answers

Last Updated :
Discuss
Comments

Question 1

What is the time complexity of Huffman Coding?

  • O(N)

  • O(NlogN)

  • O(N(logN)^2)

  • O(N^2)

Question 2

Which of the following does not use Greedy approach?

  • Huffman Coding

  • 0/1 Knapsack

  • Fractional Knapsack

  • Minimum Spanning Tree

Question 3

What is the time complexity of the greedy algorithm for the coin change problem?

  • O(n)

  • O(nlogn)

  • O(log n)

  • O(n^2)

Question 4

Which of the following standard algorithms is not a Greedy algorithm?

  • Dijkstra\'s shortest path algorithm

  • Prim\'s algorithm

  • Kruskal algorithm

  • Bellmen Ford Shortest path algorithm

Question 5

Suppose the letters a, b, c, d, e, f have probabilities 1/2, 1/4, 1/8, 1/16, 1/32, 1/32 respectively. Which of the following is the Huffman code for the letter a, b, c, d, e, f?

  • 0, 10, 110, 1110, 11110, 11111

  • 11, 10, 011, 010, 001, 000

  • 11, 10, 01, 001, 0001, 0000

  • 110, 100, 010, 000, 001, 111

Question 6

Suppose the letters a, b, c, d, e, f have probabilities 1/2, 1/4, 1/8, 1/16, 1/32, 1/32 respectively. What is the average length of Huffman codes?

  • 3

  • 2.1875

  • 2.25

  • 1.9375

Question 7

Consider the weights and values of items listed below. Note that there is only one unit of each item.

Question


The task is to pick a subset of these items such that their total weight is no more than 11 Kgs and their total value is maximized. Moreover, no item may be split. The total value of items picked by an optimal algorithm is denoted by Vopt. A greedy algorithm sorts the items by their value-to-weight ratios in descending order and packs them greedily, starting from the first item in the ordered list. The total value of items picked by the greedy algorithm is denoted by Vgreedy. The value of Vopt − Vgreedy is ______ . 

  • 16

  • 8

  • 44

  • 60

Question 8

Consider a job scheduling problem with 4 jobs J1, J2, J3, J4 and with corresponding deadlines: ( d1, d2, d3, d4) = (4, 2, 4, 2). Which of the following is not a feasible schedule without violating any job schedule?

  • J2, J4, J1, J3

  • J4, J1, J2, J3

  • J4, J2, J1, J3

  • J4, J2, J3, J1

Question 9

Consider a graph G=(V, E), where V = { v1,v2,…,v100 }, E={ (vi, vj) ∣ 1≤ i < j ≤ 100} and weight of the edge (vi, vj)  is ∣i–j∣. The weight of minimum spanning tree of G is ________.
 

  • 99

  • 100

  • 98

  • 101

Question 10

Consider the string abbccddeee. Each letter in the string must be assigned a binary code satisfying the following properties:

  • For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter.
  • For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is assigned a code whose length is at most the length of the code assigned to the other letter.

Among the set of all binary code assignments which satisfy the above two properties, what is the minimum length of the encoded string?

  • 21

  • 23

  • 25

  • 30

There are 22 questions to complete.

Take a part in the ongoing discussion