Greedy Technique: GATE CS Previous Year Questions

Greedy Technique · Algorithms

11 questions · asked in 7 of 27 years (2000–2026)

MCQ 7 · MSQ 1 · NAT 31-mark 6 · 2-mark 5

2000Questions per year2026

Questions 1–5 of 11

Q1GATE 2021 (Session 1)2 marksMSQ
Define RnR_n 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>0i > 0, let p[i]p[i] denote the selling price of a rod whose length is ii 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\text{p}[1]=1,\text{p}[2]=5,\text{p}[3]=8,\text{p}[4]=9,\text{p}[5]=10,\text{p}[6]=17,\text{p}[7]=18

which of the following statements is/are correct about R7R_7?

One or more options are correct.

Q2GATE 2021 (Session 2)2 marksMCQ−0.67 if wrong
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?

Q3GATE 20182 marksNAT
Consider the weights and values of items listed below. Note that there is only one unit of each item.
Item number Weight (in Kgs) Value (in Rupees) 11060 2728 3420 4224
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 VoptV_{opt}. 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 VgreedyV_{greedy}.
The value of VoptV_{opt}-VgreedyV_{greedy} is ____________.

Q4GATE 2017 (Session 2)2 marksNAT
A message is made up entirely of characters from the set X= {P,Q,R,S,T}. The table of probabilities for each of the characters is shown below:
Character Probability P0.22 Q0.34 R0.17 S0.19 T0.08 Total1.00
If a message of 100 characters over X is encoded using Huffman coding, then the expected length of the encoded message in bits is_____

Q5GATE 2014 (Session 2)2 marksNAT
Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is ____.

Keep practising

Topics in Algorithms

All CS topics ›