ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
optimization Directory Reference

Files

 
CoinChange.h
 The change with the fewest coins (introduction of chapter 14): the greedy choice takes the largest coin that fits, and is optimal for coins of 50, 10, 5 and 1 cents, but not for coins of 11, 5 and 1, where it pays 15 with five coins instead of three of 5.
 
CoinGame.h
 The game of the coins in a line: \( n \) coins of values \( V_0 , \ldots , V_{n-1} \) lie in a row, and two players take in turn the first or the last coin left, each one to get the most; coinsInALine() is the most the first player can be sure of, against any play of the other.
 
FractionalKnapsack.h
 The real (fractional) knapsack of section 14.1: a fraction \( x_i \in [ 0 , 1 ] \) of each object, of largest profit \( \sum_i p_i x_i \) and volume \( \sum_i v_i x_i \le C \).
 
GridPaths.h
 Two problems of dynamic programming on a matrix of \( m \) rows and \( n \) columns, each cell solved from its neighbors above and to the left:
 
HouseProblems.h
 Two problems of dynamic programming on a row of \( n \) houses, where the choice of each house depends only on the one of its neighbor:
 
IntervalCover.h
 The cover of a segment by intervals: among \( n \) closed intervals \( [ a_i , b_i ] \), the fewest whose union contains the segment \( [ \mathit{lo} , \mathit{hi} ] \), e.g., the sprinklers at \( D_i \) of radius \( R_i \), of intervals \( [ D_i - R_i , D_i + R_i ] \), that water a lawn \( [ 0 , L ] \).
 
Intervals.h
 Greedy algorithms on intervals \( [ a_i , b_i ) \) of the line:
 
Knapsack.h
 The 0-1 knapsack of section 13.6: \( n \) objects of profit \( p_i \) and volume \( v_i \), positive integers, and a knapsack of capacity \( C \); a set \( S \) of volume at most \( C \) and largest profit.
 
KnapsackVariants.h
 The relatives of the knapsack in which an item can be taken many times, and the counting versions of the knapsack, all solved by the dynamic programming on the capacity of the 0-1 knapsack of section 13.6, in pseudopolynomial time:
 
LinearPartition.h
 The linear partition problem (also the painter's partition, or the bottleneck partition of a chain): the items \( A[ 0 .. n - 1 ] \) split into \( k \) contiguous parts so that the largest sum of a part is the least, e.g., \( n \) boards of lengths \( A_i \) to be painted by \( k \) painters, each one a block of consecutive boards, in the least time.
 
OptimalSearchTree.h
 The optimal binary search tree: the keys \( 0 , \ldots , n - 1 \) are searched with the weights \( p_i \) (frequencies or probabilities), and the gaps between them, the unsuccessful searches, with the weights \( q_0 , \ldots , q_n \); the tree of least weighted path length \( \sum_i p_i ( d_i + 1 ) + \sum_j q_j d'_j \), \( d_i \) the depth of the key \( i \) and \( d'_j \) that of the external node \( j \), the root at depth 0.
 
SequenceProblems.h
 Problems of optimization on a sequence, solved by a scan or by the dynamic programming of the longest increasing subsequence [see Subsequences.h]:
 
ShortestJobFirst.h
 Shortest Job First (exercise 14.5): \( n \) programs of durations \( t_i \), run one after the other, in the order that minimizes the average time of completion: by increasing duration, since moving the shortest program to the front of any order does not increase any time of completion; \( O( n \log n ) \).
 
StockTrading.h
 The largest gain of buying and selling a stock with at most \( k \), or with exactly \( k \), transactions, given its prices on \( n \) days: a transaction buys on a day \( b \) and sells on a later day \( s \), and the transactions do not overlap, \( b_1 < s_1 < b_2 < s_2 < \cdots < b_k < s_k \).
 
WeightedIntervals.h
 The independent set of weighted intervals of section 13.2: among \( n \) intervals \( [ a_i , b_i ) \), open on the right, of weights \( w_i \), a set of disjoint ones of largest weight.