• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Greedy Algorithms with Answers

Question 11

Define Rn to be the maximum amount earned by cutting a rod of length n meters into one or more pieces of integer length and selling them. For i>0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:
p[1]=1, p[2]=5, p[3]=8, p[4]=9, p[5]=10, p[6]=17, p[7]=18 
Which of the following statements is/are correct about R7?
  • R7=18
  • R7=19
  • R7 is achieved by three different solutions
  • R7 cannot be achieved by a solution consisting of three pieces

Question 12

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

Question 13

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 ________. Note - This question was Numerical Type.
 

  • 99

  • 100

  • 98

  • 101

Question 14

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 15

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

[caption width="800"]Question[/caption]


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 16

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 17

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 18

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 19

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 20

Which of the following does not use Greedy approach?

  • Huffman Coding

  • 0/1 Knapsack

  • Fractional Knapsack

  • Minimum Spanning Tree

There are 20 questions to complete.

Last Updated :
Take a part in the ongoing discussion