Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · Greedy problem solving paradigm · Easy
What is the core idea behind the greedy algorithm paradigm?
Not quite. Try another option.
Answer: Make the choice that looks best at each step
A greedy algorithm builds a solution piece by piece, always selecting the option that appears best at the current moment (locally optimal choice).
Question 2 of 60 · Locally optimal choice · Easy
In greedy algorithms, a "locally optimal choice" refers to a decision that is:
Not quite. Try another option.
Answer: Best at the current step without considering the future
A locally optimal choice is the one that seems best at the immediate step, ignoring the effects on later decisions.
Question 3 of 60 · Global optimal choice · Easy
A greedy algorithm always produces a globally optimal solution when:
Not quite. Try another option.
Answer: The problem exhibits the greedy-choice property and optimal substructure
Greedy algorithms guarantee a global optimum only when the problem has both the greedy-choice property and optimal substructure.
Question 4 of 60 · Job Sequencing problem · Easy
In the Job Sequencing problem with deadlines, the goal is to:
Not quite. Try another option.
Answer: Maximize total profit by scheduling jobs before their deadlines
The Job Sequencing problem aims to select and order jobs to maximize profit, where each job takes one unit of time and must finish before its deadline.
Question 5 of 60 · Job Sequencing problem · Easy
To apply the greedy strategy in Job Sequencing, jobs are typically sorted by:
Not quite. Try another option.
Answer: Decreasing profit
Jobs are sorted in decreasing order of profit so the most profitable jobs are considered first for the latest available slot before their deadline.
Question 6 of 60 · Job Selection problem · Easy
In job selection problems, greedy techniques help decide which jobs to pick in order to:
Not quite. Try another option.
Answer: Optimize an objective such as maximum profit or count
Job selection uses greedy choices to pick the subset of jobs that best optimizes a target objective like profit or number of jobs completed.
Question 7 of 60 · Minimum product subset of an array · Easy
For the array , what is the minimum product subset value?
Not quite. Try another option.
Answer:
Using an odd count of negatives keeps the product negative and as large in magnitude as possible: .
Question 8 of 60 · Minimum product subset of an array · Easy
To get a negative minimum product from an array, the subset should include:
Not quite. Try another option.
Answer: An odd number of negative elements
An odd count of negative numbers yields a negative product, which is smaller than any positive product, giving the minimum.
Question 9 of 60 · Maximum product subset of an array · Easy
For the array , what is the maximum product subset value?
Not quite. Try another option.
Answer:
Choosing an even number of negatives and all positives: , the largest possible product.
Question 10 of 60 · Minimum sum of product of two arrays · Easy
To minimize the sum of products of two arrays (one element from each), you should:
Not quite. Try another option.
Answer: Sort one array ascending and the other descending
Pairing the largest element of one array with the smallest of the other (opposite orderings) minimizes the sum of the pairwise products.
Question 11 of 60 · Bin packing problem · Easy
The Bin Packing problem aims to:
Not quite. Try another option.
Answer: Pack items into the minimum number of fixed-capacity bins
Bin Packing seeks to place all items into as few bins as possible without exceeding each bin's capacity.
Question 12 of 60 · Bin packing problem · Easy
Which of the following is a common greedy heuristic for the Bin Packing problem?
Not quite. Try another option.
Answer: First Fit
First Fit is a well-known greedy heuristic that places each item into the first bin where it fits.
Question 13 of 60 · Activity Selection problem · Easy
In the Activity Selection problem, activities are greedily selected by sorting them according to their:
Not quite. Try another option.
Answer: Earliest finish time
Sorting by earliest finish time and picking non-overlapping activities greedily maximizes the number of selected activities.
Question 14 of 60 · Activity Selection problem · Easy
The objective of the Activity Selection problem is to:
Not quite. Try another option.
Answer: Select the maximum number of non-overlapping activities
The goal is to choose the largest set of mutually compatible (non-overlapping) activities that a single resource can perform.
Question 15 of 60 · Fractional Knapsack problem · Easy
In the Fractional Knapsack problem, items are chosen greedily based on their:
Not quite. Try another option.
Answer: Value-to-weight ratio
Items are sorted by decreasing value-to-weight ratio, taking as much of each as fits, allowing fractions of items.
Question 16 of 60 · Fractional Knapsack problem · Easy
Which key feature distinguishes the Fractional Knapsack from the 0/1 Knapsack problem?
Not quite. Try another option.
Answer: Items can be broken into fractions
In the Fractional Knapsack, a portion of an item can be taken, which allows a simple greedy solution unlike the 0/1 version.
Question 17 of 60 · Connect n ropes with minimum cost · Easy
In the "Connect n ropes with minimum cost" problem, which data structure is most suitable?
Not quite. Try another option.
Answer: Min-heap (priority queue)
A min-heap efficiently retrieves the two smallest ropes each time, which are joined first to minimize the total connection cost.
Question 18 of 60 · Connect n ropes with minimum cost · Easy
Given ropes of lengths , what is the minimum total cost to connect them all?
Not quite. Try another option.
Answer:
Combine , then , then ; total cost .
Question 19 of 60 · Coin change problem · Easy
The greedy approach to the Coin Change problem selects coins by:
Not quite. Try another option.
Answer: Choosing the largest denomination that does not exceed the remaining amount
The greedy method repeatedly picks the largest coin not exceeding the remaining amount, which works for canonical coin systems.
Question 20 of 60 · Majority Element · Easy
A majority element in an array of size is an element that appears more than:
Not quite. Try another option.
Answer: times
By definition, a majority element occurs more than times in the array.
Question 21 of 60 · Greedy problem solving paradigm · Medium
In a greedy algorithm, a solution is built incrementally. Which property is essential for a greedy algorithm to always produce a globally optimal solution?
Not quite. Try another option.
Answer: Greedy choice property and optimal substructure
A greedy algorithm yields an optimal solution only when the problem exhibits the greedy choice property (a local optimum leads to a global optimum) and optimal substructure (an optimal solution contains optimal solutions to subproblems).
Question 22 of 60 · Locally optimal choice · Medium
A greedy algorithm makes a locally optimal choice at each step. What is the main risk of relying only on local optimality?
Not quite. Try another option.
Answer: It may fail to reach the global optimum for some problems
Local optimality does not guarantee global optimality unless the problem has the greedy choice property. For problems like 0/1 Knapsack, purely local choices can miss the best overall solution.
Question 23 of 60 · Global optimal choice · Medium
For which of the following problems does the greedy approach guarantee a globally optimal solution?
Not quite. Try another option.
Answer: Fractional Knapsack problem
The Fractional Knapsack problem satisfies the greedy choice property; picking items by highest value-to-weight ratio yields the global optimum. The others require dynamic programming or exhaustive/approximate methods.
Question 24 of 60 · Job Sequencing problem · Medium
In the Job Sequencing with Deadlines problem, jobs are first sorted by which criterion to maximize total profit?
Not quite. Try another option.
Answer: Decreasing order of profit
Jobs are sorted in decreasing order of profit, then each job is scheduled in the latest free slot before its deadline. This maximizes total profit while respecting deadlines.
Question 25 of 60 · Job Sequencing problem · Medium
Given jobs with (profit, deadline): , , , , . What is the maximum profit achievable if each job takes one unit of time?
Not quite. Try another option.
Answer: 142
Sort by profit: . Schedule at slot 2, at slot 1, at slot 3. Total .
Question 26 of 60 · Job Selection problem · Medium
When selecting the maximum number of non-overlapping jobs (each with a start and finish time), the greedy strategy selects jobs based on:
Not quite. Try another option.
Answer: Earliest finish time
Selecting the job that finishes earliest frees the resource soonest, leaving maximum room for subsequent jobs. This greedy rule provably maximizes the count of selected non-overlapping jobs.
Question 27 of 60 · Minimum product subset of an array · Medium
For the array , what is the minimum product of a non-empty subset?
Not quite. Try another option.
Answer: -24
To minimize the product, take an odd number of negatives with all positives. Using two negatives keeps it positive, so use one pair negative and multiply: choosing with one negative gives .
Question 28 of 60 · Minimum product subset of an array · Medium
If an array contains a zero, some negatives, and some positives, when is the minimum product subset equal to a negative value rather than zero?
Not quite. Try another option.
Answer: When at least one negative number exists in the array
If any negative exists, we can form a subset with a negative product (e.g., the single most negative element), which is less than . Hence the minimum product becomes negative rather than zero.
Question 29 of 60 · Maximum product subset of an array · Medium
For the array , what is the maximum product of a non-empty subset?
Not quite. Try another option.
Answer: 24
Include all positives () and an even count of negatives. Using both s: ; using and : . Maximum is .
Question 30 of 60 · Maximum product subset of an array · Medium
To compute the maximum product subset, if the array has an odd number of negative numbers, the greedy rule is to:
Not quite. Try another option.
Answer: Exclude the negative number with the smallest absolute value
With an odd count of negatives, dropping the one closest to zero (smallest absolute value) leaves an even count and maximizes the magnitude of the positive product.
Question 31 of 60 · Minimum sum of product of two arrays · Medium
Given arrays and , the minimum sum of element-wise products (with one permutation allowed) is obtained by pairing:
Not quite. Try another option.
Answer: Largest of A with smallest of B
To minimize , sort one array ascending and the other descending (rearrangement inequality). Pair the largest of with the smallest of : .
Question 32 of 60 · Minimum sum of product of two arrays · Medium
The rearrangement inequality states that the sum is minimized when the two sequences are:
Not quite. Try another option.
Answer: Sorted in opposite orders
By the rearrangement inequality, the sum of products is minimized when one array is sorted ascending and the other descending (opposite orders), and maximized when both are in the same order.
Question 33 of 60 · Bin packing problem · Medium
In the First Fit Decreasing (FFD) heuristic for bin packing, items are processed in what order?
Not quite. Try another option.
Answer: Decreasing order of size
FFD first sorts items in decreasing order of size, then places each item into the first bin that can accommodate it. Sorting large items first typically reduces the number of bins used.
Question 34 of 60 · Bin packing problem · Medium
The bin packing problem (minimizing number of bins) is known to be:
Not quite. Try another option.
Answer: NP-hard, solved approximately by greedy heuristics
Bin packing is NP-hard. Greedy heuristics like First Fit, Best Fit, and First Fit Decreasing give good approximate (not always optimal) solutions efficiently.
Question 35 of 60 · Activity Selection problem · Medium
Given activities with (start, finish): , how many activities can be selected using the greedy earliest-finish-time rule?
Not quite. Try another option.
Answer: 3
Sort by finish time: . Select , then , then . That gives 3 non-overlapping activities.
Question 36 of 60 · Fractional Knapsack problem · Medium
In the Fractional Knapsack problem with capacity , items (value, weight) are . What is the maximum value obtainable?
Not quite. Try another option.
Answer: 240
Value/weight ratios: . Take item 1 (60, w=10) and item 2 (100, w=20), using 30 units. Fill remaining 20 with of item 3. Total .
Question 37 of 60 · Connect n ropes with minimum cost · Medium
For ropes of lengths , what is the minimum total cost to connect them all into one rope?
Not quite. Try another option.
Answer: 29
Use a min-heap. Combine (cost 5), then (cost 9), then (cost 15). Total cost .
Question 38 of 60 · Connect n ropes with minimum cost · Medium
Which data structure gives the most efficient implementation for the 'connect n ropes with minimum cost' problem?
Not quite. Try another option.
Answer: Min-heap (priority queue)
A min-heap lets us repeatedly extract the two smallest ropes in time, combine them, and reinsert the sum, achieving an overall solution.
Question 39 of 60 · Coin change problem · Medium
The greedy coin change algorithm (always picking the largest denomination) fails to give the minimum number of coins for which coin system when making amount 6?
Not quite. Try another option.
Answer: Coins
For and amount 6, greedy picks coins, but the optimal is coins. Greedy is not optimal for this non-canonical system.
Question 40 of 60 · Majority Element · Medium
The Boyer-Moore Voting Algorithm finds a majority element (appearing more than times) in:
Not quite. Try another option.
Answer: time and space
The Boyer-Moore algorithm maintains a single candidate and a count, scanning the array once in time with extra space to identify the majority element.
Question 41 of 60 · Greedy problem solving paradigm · Hard
A greedy algorithm is guaranteed to produce a globally optimal solution only when the problem exhibits which two properties?
Not quite. Try another option.
Answer: Greedy-choice property and optimal substructure
A greedy strategy yields a global optimum when a locally optimal choice can be part of a global optimum (greedy-choice property) and an optimal solution to the whole contains optimal solutions to subproblems (optimal substructure). Overlapping subproblems characterize dynamic programming, not greedy correctness.
Question 42 of 60 · Locally optimal choice · Hard
Consider making change for using coins . What is the difference between the number of coins the greedy (largest-first) approach uses versus the true optimal?
Not quite. Try another option.
Answer: Greedy uses , optimal uses ; difference
Greedy picks coins. Optimal picks coins. This demonstrates that a locally optimal choice (taking the largest coin) fails for this non-canonical coin system.
Question 43 of 60 · Job Sequencing problem · Hard
In Job Sequencing with deadlines (each job takes unit time), jobs are : . What is the maximum total profit?
Not quite. Try another option.
Answer:
Sort by profit: . Place at slot 2, can't fit slot 2 so slot 1, fails (slots 1,2 full), at slot 3. Selected .
Question 44 of 60 · Job Selection problem · Hard
When scheduling to maximize the number of non-overlapping jobs, which greedy criterion guarantees optimality?
Not quite. Try another option.
Answer: Select the job with the earliest finish time first
Sorting by earliest finish time and picking compatible jobs is provably optimal via an exchange argument: it leaves maximum room for remaining jobs. Earliest start, shortest duration, and highest profit criteria can each produce suboptimal counts.
Question 45 of 60 · Minimum product subset of an array · Hard
For the array , what is the minimum product of a non-empty subset?
Not quite. Try another option.
Answer:
There are negatives, an odd count, so we can keep the product negative. Multiply all negatives and positives: . Keeping all elements yields the most negative value here.
Question 46 of 60 · Maximum product subset of an array · Hard
For the array , what is the maximum product of a non-empty subset?
Not quite. Try another option.
Answer:
There are negatives (odd). Drop the negative with the smallest absolute value () and ignore the zero. Product ... but including gives ? No: that is . Recheck: dropping gives . Actually the maximum is by pairing all four including keeping an even count of negatives: use vs vs . Correct maximum is — but among options arises from also including magnitude; the intended answer is when the zero rule and even-negative rule combine incorrectly. Standard result: keep even negatives with largest magnitudes , times .
Question 47 of 60 · Minimum sum of product of two arrays · Hard
Given and , arranging freely (only reorder within each array), the minimum value of is:
Not quite. Try another option.
Answer:
To minimize the sum of products, pair the largest of one array with the smallest of the other. Sort ascending and descending : . Rechecking: this gives . The minimum is .
Question 48 of 60 · Bin packing problem · Hard
Which statement about the First-Fit Decreasing (FFD) heuristic for bin packing is correct?
Not quite. Try another option.
Answer: FFD uses at most bins
Bin packing is NP-hard, so FFD is a heuristic, not exact. Its proven asymptotic bound is . Sorting requires time.
Question 49 of 60 · Activity Selection problem · Hard
Activities with : . Using the earliest-finish-time greedy, how many activities can be selected?
Not quite. Try another option.
Answer:
Sorted by finish, select , then , then , then . These four are mutually compatible, and no larger compatible set exists.
Question 50 of 60 · Fractional Knapsack problem · Hard
Items : with capacity . What is the maximum value obtainable in the fractional knapsack?
Not quite. Try another option.
Answer:
Ratios: . Take item 1 fully (, kg), item 2 fully (, kg), leaving kg for item 3: . Total .
Question 51 of 60 · Connect n ropes with minimum cost · Hard
For ropes of lengths , the minimum total cost to connect them all into one rope is:
Not quite. Try another option.
Answer:
Use a min-heap. Connect (cost ), then (cost ), then (cost ). Total .
Question 52 of 60 · Coin change problem · Hard
For which of the following coin systems is the greedy (largest-coin-first) algorithm guaranteed to be optimal for every amount?
Not quite. Try another option.
Answer:
The US canonical system is canonical, so greedy is optimal. In , amount needs but greedy gives . In , amount needs but greedy gives . Similar failures occur for the last set.
Question 53 of 60 · Majority Element · Hard
In the Boyer-Moore Voting Algorithm, after the first pass finds a candidate, why is a second pass usually required?
Not quite. Try another option.
Answer: The algorithm only guarantees a candidate if a majority exists; a second pass verifies it truly appears times
Boyer-Moore's counting phase returns a candidate that is correct only under the assumption a majority exists. If no element exceeds , the candidate is spurious, so a verification pass counting its occurrences is required.
Question 54 of 60 · Problems based on greedy techniques · Hard
You want to form the largest possible number by concatenating integers from . Which comparator correctly orders two strings ?
Not quite. Try another option.
Answer: Place before if (string concatenation comparison)
The greedy rule compares concatenations: comes first if (as a string) is larger than . This yields . Numeric or length comparison fails (e.g., vs ).
Question 55 of 60 · Fractional Knapsack problem · Hard
Why does the greedy approach fail for the 0/1 Knapsack but succeed for the Fractional Knapsack?
Not quite. Try another option.
Answer: In fractional, items can be split so the ratio bound is always fully saturated; in 0/1, indivisibility can leave unusable residual capacity
Fractional knapsack lets you take partial items, so filling by decreasing value/weight ratio always uses the full capacity optimally. In 0/1, you cannot split items, so the greedy ratio choice may leave wasted capacity, breaking the greedy-choice property.
Question 56 of 60 · Job Sequencing problem · Hard
Using a Disjoint-Set (Union-Find) optimization for job sequencing with maximum deadline , the time complexity to schedule jobs becomes approximately:
Not quite. Try another option.
Answer:
Sorting jobs by profit costs . With DSU, finding the latest free slot before a deadline takes near-constant amortized time per job, giving , far better than the naive .
Question 57 of 60 · Minimum product subset of an array · Hard
For an array containing exactly one zero, some positive numbers, and an even number of negatives (all nonzero), the minimum product subset equals:
Not quite. Try another option.
Answer: The single smallest (most negative) negative element
With an even negative count, the full product of nonzeros is positive. To get the minimum (most negative), take just one negative element — the largest in absolute value. Zero () is larger than any negative, so it is not the minimum.
Question 58 of 60 · Activity Selection problem · Hard
Suppose each activity also carries a weight and we want the maximum-weight set of non-overlapping activities. Which approach is correct?
Not quite. Try another option.
Answer: Dynamic programming with binary search, since the earliest-finish greedy no longer guarantees maximum weight
The weighted interval scheduling problem is not solvable by the simple greedy; maximizing count differs from maximizing weight. It requires DP: sort by finish time and use where is found by binary search.
Question 59 of 60 · Global optimal choice · Hard
Which of the following classic problems does NOT admit a correct greedy solution guaranteeing a global optimum?
Not quite. Try another option.
Answer: 0/1 Knapsack problem
The 0/1 Knapsack lacks the greedy-choice property; picking the best ratio item can be suboptimal because items are indivisible. It requires dynamic programming. Fractional Knapsack, Huffman coding, and MST all have proven greedy optima.
Question 60 of 60 · Connect n ropes with minimum cost · Hard
If we instead wanted to MAXIMIZE the total cost of connecting ropes , which strategy and cost is correct?
Not quite. Try another option.
Answer: Use a max-heap, always combining the two largest; total
To maximize, repeatedly combine the two largest ropes so large values contribute to many sums. Steps: , , , ; cumulative cost $= 9+12+14+15... $ recomputed: ? Using two-largest each merge on : sums to . The greedy max-heap approach (not min-heap) is the correct method.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSE329 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSE329 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.