Greedy Algorithms: past questions

26 questions · 84 marks · 10 papers. Try each one before checking.

Solve them and check answers →Read the notes first

03 Aug 2025

Question 9 MCQ · 3 marks

Lets consider a message with characters and frequencies as given below.

Characters $A$ $B$ $C$ $D$
Frequencies 50 20 2 10

What is the total bits required to store above message using the Huffman coding algorithm?

  1. 328

  2. 82

  3. 100

  4. 126

Question 7 MCQ · 3 marks

Consider the following statements and select the correct option. i. The greedy technique always gives an optimized solution to the problem. ii. Bellman-Ford and Floyd-Warshal algorithms use the greedy technique to solve the path problems.

  1. Statements (i) and (ii) are false.

  2. Statements (i) and (ii) are true.

  3. Statement (i) is true and Statement (ii) is false.

  4. Statement (i) is false and Statement (ii) is true.

July 2022

Question 7 MCQ · 4 marks

Which of the following is the correct length of codes for the character set $S = \{A, B, C, D, E, F\}$, generated using the Huffman algorithm for given frequencies?

Character A B C D E F
Frequency 13 30 6 35 2 11
  1. A-3, B-3, C-5, D-1, E-5, F-4

  2. A-3, B-2, C-5, D-2, E-5, F-4

  3. A-3, B-3, C-5, D-2, E-5, F-4

  4. A-3, B-2, C-5, D-1, E-5, F-4

Question 13 SA · 4 marks

Meetings M1, M2, ....., M11 are to be conducted in a single available meeting room. The table below gives the start and end times of these meetings. If any activity finishes at time $T$, then other activities can be started at time $T$ or afterward. What is the maximum number of meetings that can be held in the meeting room without conflicts?

M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11
Start 5 4 8 9 12 7 5 3 4 1 8
End 7 5 10 11 14 9 8 5 9 3 13

This question has a figure: open the interactive page.

Type your answer on the interactive page.

01 Dec 2024

Question 17 MCQ · 4 marks

Given the following set of characters and their frequencies:

Character Frequency
A 11
B 5
C 6
D 2
E 12
F 24

Using Huffman coding, construct the Huffman tree for this set of characters. What is the total number of bits needed to represent the message ABCDEF?

  1. 15 bits

  2. 16 bits

  3. 17 bits

  4. 18 bits

Question 12 SA · 3 marks

For an activity $X$, $X_s$ is the starting time and $X_e$ is the ending time. The following are the starting time and ending time of activities A, B, C, D, E, F, G, H and I given in chronological order. $A_s, B_s, C_s, A_e, C_e, D_s, E_s, B_e, F_s, G_s, H_s, E_e, I_s, D_e, F_e, G_e, H_e, I_e$ What is the minimum number of rooms required to schedule the activities in a set of rooms such that there are no conflicts?

Type your answer on the interactive page.

Question 6 MCQ · 3 marks

Let you have a single positive integer $x$, which is initially equal to 1. You are given a positive integer $n$ where $n > x$. In each step, you can either increment $x$ by 1 or double $x$. Your goal is to produce a target value $n$ in minimum number of steps. For example, you can produce the integer $n = 10$ in minimum four steps as follows: $1(+1) \to 2(*2) \to 4(+1) \to 5(*2) \to 10$ What is the minimum number of steps required if $n = 725$?

  1. 14

  2. 15

  3. 16

  4. 17

06 Apr 2026

Question 6 MCQ · 3 marks

Suppose the letters $\{a, b, c, d, e\}$ occur with the following frequencies.

Character a b c d e
Frequencies 26 21 16 30 7

How many bits will be used to encode the letter b in the Huffman code for this alphabet?

  1. 1

  2. 2

  3. 3

  4. 4

Question 14 SA · 4 marks

In the table below, we have 9 activities with the corresponding start and finish times. It might not be possible to complete all the activities since their time frames can conflict. For example, if any activity starts at time 0 and finishes at time 4, then other activities can not begin before 4. It can be started at 4 or later. What is the maximum number of activities which can be performed without conflict?

Activity Start time Finish time
A 1 4
B 3 4
C 10 11
D 2 3
E 4 5
F 7 9
G 11 14
H 6 8
I 5 9

This question has a figure: open the interactive page.

Type your answer on the interactive page.

Question 7 MCQ · 3 marks

Consider a set of activities $A_1, A_2, \dots, A_n$, where each activity $A_i$ has: a processing time $T_i$ (time required to complete the activity), and a deadline $D_i$. Only one activity can be executed at a time. If an activity finishes at time $t$, the next activity can start at time $t$ itself. Assume that the initial start time is 0. The lateness of an activity $A_i$ is defined as:

$$L(i) = \begin{cases} F_i - D_i, & \text{if } F_i > D_i \\ 0, & \text{otherwise} \end{cases}$$

where $F_i$ denotes the finish time of activity $A_i$. Let $M_L$ denote the maximum lateness among all activities: $M_L = \max(L_1, L_2, \dots, L_n)$. The objective is to schedule the activities in an order that minimizes $M_L$. Which of the following greedy strategies will always produce an optimal schedule for minimizing the maximum lateness $M_L$?

  1. Always schedule first the activity with the minimum processing time.

  2. Always schedule first the activity with the earliest deadline.

  3. Always schedule first the activity with the minimum value of $D_i - T_i$.

  4. Always schedule first the activity with the maximum processing time.

Aug 2023

Question 12 SA · 3 marks

An entire message is created using characters from the set $S = \{A, B, C, D, E\}$. The probability of occurrence of each character is given in the table below.

A B C D E
0.22 0.21 0.16 0.30 0.11

How many bits will be used to encode the message ABCDE using Huffman codes?

Type your answer on the interactive page.

Question 13 MCQ · 3 marks

Meetings M1, M2, ....., M10 are to be conducted in a single available meeting room. The table below gives the start and end times of these meetings. If any activity finishes at time $T$, then other activities can be started at time $T$ or afterward.

M1 M2 M3 M4 M5 M6 M7 M8 M9 M10
start 3 2 8 4 10 1 12 3 1 6
end 6 3 11 6 11 2 13 5 3 9

How many meetings can be scheduled at most by following the timing constraints given above?

This question has a figure: open the interactive page.

  1. 4

  2. 5

  3. 6

  4. 7

Dec 2023

Question 7 MCQ · 3 marks

Given the following set of characters and their frequencies:

Character Frequency
A 80
B 60
C 50
D 40
E 30
F 20

Using Huffman coding, construct the Huffman tree for this set of characters. What is the total number of bits needed to represent the message ABCDEF?

  1. 15 bits

  2. 16 bits

  3. 17 bits

  4. 18 bits

Question 8 MCQ · 3 marks

Suppose you have a set of jobs with their start and end times. If any job finishes at a time $T$, then the other job can be scheduled at a time $T$ or afterward. Your goal is to find the maximum number of non-overlapping jobs that can be scheduled. Which of the following greedy strategy can be used to solve this problem optimally?

  1. Select jobs with the earliest start times first.

  2. Select jobs with the earliest end times first.

  3. Select jobs with the shortest duration first.

  4. Select jobs with the longest duration first.

16 Mar 2025

Question 11 MCQ · 4 marks

Given below is the frequencies for the character set $S = \{A, B, C, D, E, F\}$.

Character A B C D E F
Frequency 13 30 6 35 2 11

Huffman encoding is applied on the above character set. Which of the following is the correct length of codes for the character set?

  1. $A-3, B-3, C-5, D-1, E-5, F-4$

  2. $A-3, B-2, C-5, D-2, E-5, F-4$

  3. $A-3, B-3, C-5, D-2, E-5, F-4$

  4. $A-3, B-2, C-5, D-1, E-5, F-4$

Question 9 MCQ · 3 marks

You are given the following list of 8 meeting requests with start time, and end time.

Meeting Id Start Time End Time
1 1 4
2 1 2
3 5 8
4 7 10
5 6 8
6 11 16
7 15 20
8 14 17

Each meeting requires its own conference room. Your goal is to schedule all meetings in the minimum number of conference rooms. Assume that if any meeting ends at time $t$, then another meeting can start at time $t$ or afterwards in the same room. The minimum number of conference rooms required to schedule all meetings is ___

This question has a figure: open the interactive page.

  1. 3

  2. 4

  3. 5

  4. 6

Question 5 MCQ · 3 marks

Consider the following activities $A_1, A_2, \dots, A_7$.

Task $A_1$ $A_2$ $A_3$ $A_4$ $A_5$ $A_6$ $A_7$
Activity Duration($T$) 4 2 1 4 3 2 5
Deadline($D$) 14 4 9 7 19 2 12

We can execute one activity at a time. Each activity $A_i$ has activity duration $T_i$ which represents the time required to complete and a deadline $D_i$. Consider the initial start time 0 to start the first selected activity. Let the lateness of a schedule be the maximum amount by which any single activity is late in that schedule. What is the minimum lateness across all possible schedules?

  1. 2

  2. 3

  3. 4

  4. 5

24 Mar 2024

Question 10 MSQ · 2 marks

For a set of symbols with probabilities of occurrence, which of the following statement(s) about the Huffman tree is/are correct?

  1. Symbols with higher probabilities are generally closer to the root of the tree

  2. Symbols with lower probabilities are generally closer to the root of the tree

  3. The Huffman tree is always a complete binary tree

  4. It generates prefix codes (no code is a prefix of another).

Question 16 SA · 4 marks

You are given a list of 7 activities to be conducted in a single available room, each represented by (start time, end time). If any activity finishes at time $T$, then another activity can be started at time $T$ or afterwards. Activities: [(1, 4), (3, 5), (0, 2), (2, 3), (5, 8), (8, 9), (5, 7)] How many activities can be scheduled at most by following the timing constraints given above?

This question has a figure: open the interactive page.

Type your answer on the interactive page.

Question 17 SA · 4 marks

You are given a list of 8 meetings, each represented by a tuple (start time, end time). Your goal is to schedule all meetings in the minimum number of conference rooms. If a meeting ends at time $t$ in a conference room, another meeting can start at time $t$ or afterwards in the same room. Meetings: [(1, 4), (6, 12), (2, 8), (11, 15), (3, 7), (5, 10), (9, 14), (13, 16)] The minimum number of conference rooms needed to schedule all meetings is ___.

This question has a figure: open the interactive page.

Type your answer on the interactive page.

04 Aug 2024

Question 16 MSQ · 3 marks

For a set of symbols with probabilities of occurrence, which of the following statement(s) is/are true about the Huffman algorithm?

  1. Symbols with lower probabilities value are generally closer to the root of the Huffman tree.

  2. The Huffman tree is always a strict binary tree (each node has two children, except leaf nodes).

  3. It generates prefix codes (no code is a prefix of another).

  4. If probability values are distinct, then two symbols with the lowest probabilities always have the same code length.

  5. There is always at least one symbol with a code of length one.

Question 10 MCQ · 3 marks

Consider the following activities $A_1, A_2, \dots, A_6$.

Task $A_1$ $A_2$ $A_3$ $A_4$ $A_5$ $A_6$
Activity Duration($T$) 4 2 1 4 3 2
Deadline($D$) 6 7 8 12 14 5

We can execute one activity at a time. Each activity $A_i$ has activity duration $T_i$ which represents the time required to complete and a deadline $D_i$. Consider the initial start time 0 to start the first activity. The lateness of each job $i$ is defined as follows:

$$L(i) = \begin{cases} \text{Finish Time}(F_i) - \text{Deadline}(D_i) & \text{if } \text{Finish Time}(F_i) > \text{Deadline}(D_i) \\ 0 & \text{else} \end{cases}$$

Suppose $M_L$ is the maximum lateness of all activities lateness:- $M_L = \text{Max}(L_1, L_2, \dots, L_n)$ What will be minimum possible value of $M_L$?

  1. 4

  2. 3

  3. 2

  4. 1

Question 17 MSQ · 3 marks

Let coins be a list of $k$ coin denominations (positive integers) that are available in as much quantity as you want. You want to pay a sum of Rupees $x$ using as few coins as possible from the coin denominations given in the list coins. Consider the following greedy strategy: Sort the coin denominations in descending order, and then repeatedly choose the largest coin denomination that is less than or equal to the remaining amount $x$. We subtract the chosen coin value from $x$ and continue this process until $x$ becomes zero. Which of the following is/are counter-example(s) that prove that a given greedy strategy is not optimum?

  1. coins = [1, 2, 8, 9, 5, 10] and $x = 13$

  2. coins = [10, 1, 2, 5] and $x = 25$

  3. coins = [6, 1, 5, 7] and $x = 15$

  4. coins = [1, 6, 7, 10, 15] and $x = 35$

  5. coins = [1, 2, 5, 10, 25] and $x = 40$

14 Aug 2026

Question 8 MCQ · 3 marks

You are verifying a set of binary codes generated for a text file containing four unique characters: $\{A, B, C, D\}$. Which of the following code allocations is invalid because it violates the fundamental prefix property required by Huffman coding?

  1. $A: 0, B: 1, C: 01, D: 10$

  2. $A: 0, B: 10, C: 110, D: 111$

  3. $A: 1, B: 01, C: 001, D: 000$

  4. $A: 00, B: 01, C: 10, D: 11$

Question 10 MCQ · 3 marks

A text file contains 1000 characters. Originally, each character is represented using a fixed-length code of 4 bits. After applying Huffman coding, the average code length becomes 3 bits per character. What percentage reduction in storage is achieved?

  1. 20

  2. 25

  3. 30

  4. 33.33

Question 9 MCQ · 3 marks

Consider the following activities represented as (Start Time, Finish Time): $A1 = (8, 11)$ $A2 = (1, 4)$ $A3 = (3, 5)$ $A4 = (0, 6)$ $A5 = (5, 7)$ $A6 = (3, 9)$ $A7 = (5, 9)$ $A8 = (6, 10)$ $A9 = (8, 12)$ $A10 = (12, 14)$

Two activities are considered compatible if the start time of one activity is greater than or equal to the finish time of the previously selected activity. A greedy algorithm is used to select the maximum number of non-overlapping activities. How many activities will be selected?

This question has a figure: open the interactive page.

  1. 3

  2. 4

  3. 5

  4. 6

Check your answers →

Other PDSA topics