1What is the core idea behind the greedy algorithm paradigm?
Greedy problem solving paradigm
Easy
A.Make the choice that looks best at each step
B.Break the problem into overlapping subproblems
C.Randomly select choices until a solution is found
D.Try all possible combinations exhaustively
Correct Answer: Make the choice that looks best at each step
Explanation:
A greedy algorithm builds a solution piece by piece, always selecting the option that appears best at the current moment (locally optimal choice).
Incorrect! Try again.
2In greedy algorithms, a "locally optimal choice" refers to a decision that is:
Locally optimal choice
Easy
A.Best at the current step without considering the future
B.Based on solving all subproblems first
C.Best for the entire problem globally
D.Chosen at random from valid options
Correct Answer: Best at the current step without considering the future
Explanation:
A locally optimal choice is the one that seems best at the immediate step, ignoring the effects on later decisions.
Incorrect! Try again.
3A greedy algorithm always produces a globally optimal solution when:
Global optimal choice
Easy
A.All elements in the input are equal
B.The problem exhibits the greedy-choice property and optimal substructure
C.The input array is sorted in ascending order
D.The problem size is very small
Correct Answer: The problem exhibits the greedy-choice property and optimal substructure
Explanation:
Greedy algorithms guarantee a global optimum only when the problem has both the greedy-choice property and optimal substructure.
Incorrect! Try again.
4In the Job Sequencing problem with deadlines, the goal is to:
Job Sequencing problem
Easy
A.Minimize the number of jobs scheduled
B.Minimize the total time taken for all jobs
C.Schedule every job regardless of deadline
D.Maximize total profit by scheduling jobs before their deadlines
Correct Answer: Maximize total profit by scheduling jobs before their deadlines
Explanation:
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.
Incorrect! Try again.
5To apply the greedy strategy in Job Sequencing, jobs are typically sorted by:
Job Sequencing problem
Easy
A.Increasing profit
B.Decreasing profit
C.Job name alphabetically
D.Increasing deadline
Correct Answer: Decreasing profit
Explanation:
Jobs are sorted in decreasing order of profit so the most profitable jobs are considered first for the latest available slot before their deadline.
Incorrect! Try again.
6In job selection problems, greedy techniques help decide which jobs to pick in order to:
Job Selection problem
Easy
A.Guarantee all jobs are always selected
B.Optimize an objective such as maximum profit or count
C.Sort the jobs by their identifiers
D.Minimize the memory used by the program
Correct Answer: Optimize an objective such as maximum profit or count
Explanation:
Job selection uses greedy choices to pick the subset of jobs that best optimizes a target objective like profit or number of jobs completed.
Incorrect! Try again.
7For the array , what is the minimum product subset value?
Minimum product subset of an array
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Using an odd count of negatives keeps the product negative and as large in magnitude as possible: .
Incorrect! Try again.
8To get a negative minimum product from an array, the subset should include:
Minimum product subset of an array
Easy
A.An even number of negative elements
B.Exactly one zero element
C.Only positive elements
D.An odd number of negative elements
Correct Answer: An odd number of negative elements
Explanation:
An odd count of negative numbers yields a negative product, which is smaller than any positive product, giving the minimum.
Incorrect! Try again.
9For the array , what is the maximum product subset value?
Maximum product subset of an array
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Choosing an even number of negatives and all positives: , the largest possible product.
Incorrect! Try again.
10To minimize the sum of products of two arrays (one element from each), you should:
Minimum sum of product of two arrays
Easy
A.Sort both arrays in ascending order
B.Leave both arrays in their original order
C.Sort both arrays in descending order
D.Sort one array ascending and the other descending
Correct Answer: Sort one array ascending and the other descending
Explanation:
Pairing the largest element of one array with the smallest of the other (opposite orderings) minimizes the sum of the pairwise products.
Incorrect! Try again.
11The Bin Packing problem aims to:
Bin packing problem
Easy
A.Maximize the number of bins used
B.Fill a single bin with the most valuable items
C.Sort bins by their capacity
D.Pack items into the minimum number of fixed-capacity bins
Correct Answer: Pack items into the minimum number of fixed-capacity bins
Explanation:
Bin Packing seeks to place all items into as few bins as possible without exceeding each bin's capacity.
Incorrect! Try again.
12Which of the following is a common greedy heuristic for the Bin Packing problem?
Bin packing problem
Easy
A.First Fit
B.Binary Search
C.Depth First Search
D.Merge Sort
Correct Answer: First Fit
Explanation:
First Fit is a well-known greedy heuristic that places each item into the first bin where it fits.
Incorrect! Try again.
13In the Activity Selection problem, activities are greedily selected by sorting them according to their:
Activity Selection problem
Easy
A.Earliest finish time
B.Longest duration
C.Earliest start time
D.Latest finish time
Correct Answer: Earliest finish time
Explanation:
Sorting by earliest finish time and picking non-overlapping activities greedily maximizes the number of selected activities.
Incorrect! Try again.
14The objective of the Activity Selection problem is to:
Activity Selection problem
Easy
A.Select every available activity
B.Select the maximum number of non-overlapping activities
C.Minimize the total time of all activities
D.Select the activity with the longest duration
Correct Answer: Select the maximum number of non-overlapping activities
Explanation:
The goal is to choose the largest set of mutually compatible (non-overlapping) activities that a single resource can perform.
Incorrect! Try again.
15In the Fractional Knapsack problem, items are chosen greedily based on their:
Fractional Knapsack problem
Easy
A.Weight only
B.Value-to-weight ratio
C.Alphabetical order
D.Value only
Correct Answer: Value-to-weight ratio
Explanation:
Items are sorted by decreasing value-to-weight ratio, taking as much of each as fits, allowing fractions of items.
Incorrect! Try again.
16Which key feature distinguishes the Fractional Knapsack from the 0/1 Knapsack problem?
Fractional Knapsack problem
Easy
A.The knapsack has no capacity limit
B.Only one item can be selected
C.Items must be taken whole
D.Items can be broken into fractions
Correct Answer: Items can be broken into fractions
Explanation:
In the Fractional Knapsack, a portion of an item can be taken, which allows a simple greedy solution unlike the 0/1 version.
Incorrect! Try again.
17In the "Connect n ropes with minimum cost" problem, which data structure is most suitable?
Connect n ropes with minimum cost
Easy
A.Hash table
B.Max-heap only
C.Stack
D.Min-heap (priority queue)
Correct Answer: Min-heap (priority queue)
Explanation:
A min-heap efficiently retrieves the two smallest ropes each time, which are joined first to minimize the total connection cost.
Incorrect! Try again.
18Given ropes of lengths , what is the minimum total cost to connect them all?
Connect n ropes with minimum cost
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Combine , then , then ; total cost .
Incorrect! Try again.
19The greedy approach to the Coin Change problem selects coins by:
Coin change problem
Easy
A.Trying every possible combination
B.Choosing coins in random order
C.Choosing the largest denomination that does not exceed the remaining amount
D.Choosing the smallest denomination first
Correct Answer: Choosing the largest denomination that does not exceed the remaining amount
Explanation:
The greedy method repeatedly picks the largest coin not exceeding the remaining amount, which works for canonical coin systems.
Incorrect! Try again.
20A majority element in an array of size is an element that appears more than:
Majority Element
Easy
A. times
B. times
C. times
D. times
Correct Answer: times
Explanation:
By definition, a majority element occurs more than times in the array.
Incorrect! Try again.
21In a greedy algorithm, a solution is built incrementally. Which property is essential for a greedy algorithm to always produce a globally optimal solution?
Greedy problem solving paradigm
Medium
A.Overlapping subproblems and memoization
B.Greedy choice property and optimal substructure
C.Divide and conquer decomposition
D.Backtracking with pruning
Correct Answer: Greedy choice property and optimal substructure
Explanation:
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).
Incorrect! Try again.
22A greedy algorithm makes a locally optimal choice at each step. What is the main risk of relying only on local optimality?
Locally optimal choice
Medium
A.It requires exponential memory
B.It may fail to reach the global optimum for some problems
C.It cannot be implemented iteratively
D.It always increases time complexity
Correct Answer: It may fail to reach the global optimum for some problems
Explanation:
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.
Incorrect! Try again.
23For which of the following problems does the greedy approach guarantee a globally optimal solution?
Global optimal choice
Medium
A.Longest common subsequence
B.0/1 Knapsack problem
C.Traveling salesman problem
D.Fractional Knapsack problem
Correct Answer: Fractional Knapsack problem
Explanation:
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.
Incorrect! Try again.
24In the Job Sequencing with Deadlines problem, jobs are first sorted by which criterion to maximize total profit?
Job Sequencing problem
Medium
A.Decreasing order of profit
B.Decreasing order of deadline
C.Increasing order of profit
D.Increasing order of deadline
Correct Answer: Decreasing order of profit
Explanation:
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.
Incorrect! Try again.
25Given jobs with (profit, deadline): , , , , . What is the maximum profit achievable if each job takes one unit of time?
Job Sequencing problem
Medium
A.142
B.100
C.127
D.115
Correct Answer: 142
Explanation:
Sort by profit: . Schedule at slot 2, at slot 1, at slot 3. Total .
Incorrect! Try again.
26When selecting the maximum number of non-overlapping jobs (each with a start and finish time), the greedy strategy selects jobs based on:
Job Selection problem
Medium
A.Shortest duration
B.Earliest finish time
C.Longest duration
D.Earliest start time
Correct Answer: Earliest finish time
Explanation:
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.
Incorrect! Try again.
27For the array , what is the minimum product of a non-empty subset?
Minimum product subset of an array
Medium
A.24
B.-8
C.-24
D.-12
Correct Answer: -24
Explanation:
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 .
Incorrect! Try again.
28If an array contains a zero, some negatives, and some positives, when is the minimum product subset equal to a negative value rather than zero?
Minimum product subset of an array
Medium
A.Only when the count of negatives is even
B.When at least one negative number exists in the array
C.Only when no positives are present
D.When at least two negatives exist
Correct Answer: When at least one negative number exists in the array
Explanation:
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.
Incorrect! Try again.
29For the array , what is the maximum product of a non-empty subset?
Maximum product subset of an array
Medium
A.48
B.-24
C.24
D.12
Correct Answer: 24
Explanation:
Include all positives () and an even count of negatives. Using both s: ; using and : . Maximum is .
Incorrect! Try again.
30To compute the maximum product subset, if the array has an odd number of negative numbers, the greedy rule is to:
Maximum product subset of an array
Medium
A.Include all negatives
B.Exclude the negative number with the smallest absolute value
C.Exclude the negative number with the largest absolute value
D.Exclude all negatives
Correct Answer: Exclude the negative number with the smallest absolute value
Explanation:
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.
Incorrect! Try again.
31Given arrays and , the minimum sum of element-wise products (with one permutation allowed) is obtained by pairing:
Minimum sum of product of two arrays
Medium
A.Sorting both in the same order
B.Largest of A with largest of B
C.Largest of A with smallest of B
D.Pairing equal-index elements as given
Correct Answer: Largest of A with smallest of B
Explanation:
To minimize , sort one array ascending and the other descending (rearrangement inequality). Pair the largest of with the smallest of : .
Incorrect! Try again.
32The rearrangement inequality states that the sum is minimized when the two sequences are:
Minimum sum of product of two arrays
Medium
A.Sorted in opposite orders
B.Both kept unsorted
C.Both randomly shuffled
D.Sorted in the same order
Correct Answer: Sorted in opposite orders
Explanation:
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.
Incorrect! Try again.
33In the First Fit Decreasing (FFD) heuristic for bin packing, items are processed in what order?
Bin packing problem
Medium
A.Decreasing order of size
B.Increasing order of size
C.Random order
D.Order of arrival
Correct Answer: Decreasing order of size
Explanation:
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.
Incorrect! Try again.
34The bin packing problem (minimizing number of bins) is known to be:
Bin packing problem
Medium
A.Solvable optimally in by greedy
B.Solvable optimally by a simple greedy algorithm
C.Solvable in linear time
D.NP-hard, solved approximately by greedy heuristics
Correct Answer: NP-hard, solved approximately by greedy heuristics
Explanation:
Bin packing is NP-hard. Greedy heuristics like First Fit, Best Fit, and First Fit Decreasing give good approximate (not always optimal) solutions efficiently.
Incorrect! Try again.
35Given activities with (start, finish): , how many activities can be selected using the greedy earliest-finish-time rule?
Activity Selection problem
Medium
A.5
B.3
C.2
D.4
Correct Answer: 3
Explanation:
Sort by finish time: . Select , then , then . That gives 3 non-overlapping activities.
Incorrect! Try again.
36In the Fractional Knapsack problem with capacity , items (value, weight) are . What is the maximum value obtainable?
Fractional Knapsack problem
Medium
A.220
B.160
C.240
D.180
Correct Answer: 240
Explanation:
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 .
Incorrect! Try again.
37For ropes of lengths , what is the minimum total cost to connect them all into one rope?
Connect n ropes with minimum cost
Medium
A.33
B.27
C.30
D.29
Correct Answer: 29
Explanation:
Use a min-heap. Combine (cost 5), then (cost 9), then (cost 15). Total cost .
Incorrect! Try again.
38Which data structure gives the most efficient implementation for the 'connect n ropes with minimum cost' problem?
Connect n ropes with minimum cost
Medium
A.Hash table
B.Stack
C.Max-heap
D.Min-heap (priority queue)
Correct Answer: Min-heap (priority queue)
Explanation:
A min-heap lets us repeatedly extract the two smallest ropes in time, combine them, and reinsert the sum, achieving an overall solution.
Incorrect! Try again.
39The 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?
Coin change problem
Medium
A.Coins
B.Coins
C.Coins
D.Coins
Correct Answer: Coins
Explanation:
For and amount 6, greedy picks coins, but the optimal is coins. Greedy is not optimal for this non-canonical system.
Incorrect! Try again.
40The Boyer-Moore Voting Algorithm finds a majority element (appearing more than times) in:
Majority Element
Medium
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
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.
Incorrect! Try again.
41A greedy algorithm is guaranteed to produce a globally optimal solution only when the problem exhibits which two properties?
Greedy problem solving paradigm
Hard
A.Optimal substructure and overlapping subproblems
B.Greedy-choice property and optimal substructure
C.Greedy-choice property and overlapping subproblems
D.Overlapping subproblems and memoization
Correct Answer: Greedy-choice property and optimal substructure
Explanation:
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.
Incorrect! Try again.
42Consider making change for using coins . What is the difference between the number of coins the greedy (largest-first) approach uses versus the true optimal?
Greedy picks coins. Optimal picks coins. This demonstrates that a locally optimal choice (taking the largest coin) fails for this non-canonical coin system.
Incorrect! Try again.
43In Job Sequencing with deadlines (each job takes unit time), jobs are : . What is the maximum total profit?
Job Sequencing problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Sort by profit: . Place at slot 2, can't fit slot 2 so slot 1, fails (slots 1,2 full), at slot 3. Selected .
Incorrect! Try again.
44When scheduling to maximize the number of non-overlapping jobs, which greedy criterion guarantees optimality?
Job Selection problem
Hard
A.Select the job with the earliest finish time first
B.Select the job with the earliest start time first
C.Select the job with the highest profit first
D.Select the job with the shortest duration first
Correct Answer: Select the job with the earliest finish time first
Explanation:
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.
Incorrect! Try again.
45For the array , what is the minimum product of a non-empty subset?
Minimum product subset of an array
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
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.
Incorrect! Try again.
46For the array , what is the maximum product of a non-empty subset?
Maximum product subset of an array
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
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 .
Incorrect! Try again.
47Given and , arranging freely (only reorder within each array), the minimum value of is:
Minimum sum of product of two arrays
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
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 .
Incorrect! Try again.
48Which statement about the First-Fit Decreasing (FFD) heuristic for bin packing is correct?
Bin packing problem
Hard
A.FFD always finds the optimal number of bins
B.FFD runs in time without sorting
C.FFD uses at most bins
D.FFD uses at most bins and no better bound exists
Correct Answer: FFD uses at most bins
Explanation:
Bin packing is NP-hard, so FFD is a heuristic, not exact. Its proven asymptotic bound is . Sorting requires time.
Incorrect! Try again.
49Activities with : . Using the earliest-finish-time greedy, how many activities can be selected?
Activity Selection problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Sorted by finish, select , then , then , then . These four are mutually compatible, and no larger compatible set exists.
Incorrect! Try again.
50Items : with capacity . What is the maximum value obtainable in the fractional knapsack?
Fractional Knapsack problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Ratios: . Take item 1 fully (, kg), item 2 fully (, kg), leaving kg for item 3: . Total .
Incorrect! Try again.
51For ropes of lengths , the minimum total cost to connect them all into one rope is:
Connect n ropes with minimum cost
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Use a min-heap. Connect (cost ), then (cost ), then (cost ). Total .
Incorrect! Try again.
52For which of the following coin systems is the greedy (largest-coin-first) algorithm guaranteed to be optimal for every amount?
Coin change problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
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.
Incorrect! Try again.
53In the Boyer-Moore Voting Algorithm, after the first pass finds a candidate, why is a second pass usually required?
Majority Element
Hard
A.The algorithm only guarantees a candidate if a majority exists; a second pass verifies it truly appears times
B.The first pass sorts the array, so verification confirms the sort order
C.The second pass is needed to compute the exact index of the majority element
D.The candidate from pass one is always wrong and must be corrected
Correct Answer: The algorithm only guarantees a candidate if a majority exists; a second pass verifies it truly appears times
Explanation:
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.
Incorrect! Try again.
54You want to form the largest possible number by concatenating integers from . Which comparator correctly orders two strings ?
Problems based on greedy techniques
Hard
A.Place before if (string concatenation comparison)
B.Place before if
C.Place before if
D.Place before if numerically
Correct Answer: Place before if (string concatenation comparison)
Explanation:
The greedy rule compares concatenations: comes first if (as a string) is larger than . This yields . Numeric or length comparison fails (e.g., vs ).
Incorrect! Try again.
55Why does the greedy approach fail for the 0/1 Knapsack but succeed for the Fractional Knapsack?
B.In 0/1, values are always negative, making greedy invalid
C.In fractional, items can be split so the ratio bound is always fully saturated; in 0/1, indivisibility can leave unusable residual capacity
D.Fractional knapsack has no weight constraint, so greedy trivially works
Correct Answer: In fractional, items can be split so the ratio bound is always fully saturated; in 0/1, indivisibility can leave unusable residual capacity
Explanation:
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.
Incorrect! Try again.
56Using a Disjoint-Set (Union-Find) optimization for job sequencing with maximum deadline , the time complexity to schedule jobs becomes approximately:
Job Sequencing problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
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 .
Incorrect! Try again.
57For an array containing exactly one zero, some positive numbers, and an even number of negatives (all nonzero), the minimum product subset equals:
Minimum product subset of an array
Hard
A.The product of all negative elements
B.The product of the two smallest elements
C.The product of all elements including zero, i.e.,
D.The single smallest (most negative) negative element
Correct Answer: The single smallest (most negative) negative element
Explanation:
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.
Incorrect! Try again.
58Suppose each activity also carries a weight and we want the maximum-weight set of non-overlapping activities. Which approach is correct?
Activity Selection problem
Hard
A.Dynamic programming with binary search, since the earliest-finish greedy no longer guarantees maximum weight
B.Sort by weight descending and greedily pick compatible activities
C.Sort by start time and pick greedily
D.The same earliest-finish-time greedy still gives the optimal weight
Correct Answer: Dynamic programming with binary search, since the earliest-finish greedy no longer guarantees maximum weight
Explanation:
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.
Incorrect! Try again.
59Which of the following classic problems does NOT admit a correct greedy solution guaranteeing a global optimum?
Global optimal choice
Hard
A.Huffman coding
B.0/1 Knapsack problem
C.Fractional Knapsack problem
D.Minimum Spanning Tree (Kruskal's)
Correct Answer: 0/1 Knapsack problem
Explanation:
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.
Incorrect! Try again.
60If we instead wanted to MAXIMIZE the total cost of connecting ropes , which strategy and cost is correct?
Connect n ropes with minimum cost
Hard
A.Order does not affect total cost
B.Use a min-heap as usual; total
C.Use a max-heap; total
D.Use a max-heap, always combining the two largest; total
Correct Answer: Use a max-heap, always combining the two largest; total
Explanation:
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.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. 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.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →