Greedy Technique


Question 1
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?
A
21
B
23
C
25
D
30
GATE CSE 2021 SET-2   Algorithm
Question 2
Define R_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 > 0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:

\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 R_7?
[MSQ]
A
R_7=18
B
R_7=19
C
R_7 is achieved by three different solutions.
D
R_7 cannot be achieved by a solution consisting of three pieces.
GATE CSE 2021 SET-1   Algorithm


Question 3
Huffman tree is constructed for the following data :{A,B,C,D,E} with frequency {0.17, 0.11, 0.24, 0.33 and 0.15} respectively. 100 00 01101 is decoded as
A
BACE
B
CADE
C
BAD
D
CADD
ISRO CSE 2020   Algorithm
Question 4
Consider the weights and values of items listed below. Note that there is only one unit of each item.

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 V_{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 V_{greedy}.
The value of V_{opt}-V_{greedy} is ____________.
A
36
B
40
C
16
D
0
GATE CSE 2018   Algorithm
Question 5
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:

If a message of 100 characters over X is encoded using Huffman coding, then the expected length of the encoded message in bits is_____
A
225
B
115
C
275
D
315
GATE CSE 2017 SET-2   Algorithm


There are 5 questions to complete.

2 thoughts on “Greedy Technique”

  1. I have a request to the site owner that please don’t upload the options for Numerical Type Question[NAT], just make it as correct or wrong, if possible.

    Reply

Leave a Comment