-
Notifications
You must be signed in to change notification settings - Fork 21k
Open
Labels
Description
What would you like to Propose?
I want to add an implementation of the Optimal Binary Search Tree algorithm
Optimal Binary Search Tree is a classic dynamic programming algorithm that computes the minimum weighted search cost for a set of keys and their access frequencies.
https://en.wikipedia.org/wiki/Optimal_binary_search_tree
Issue details
Expected behavior:
Given arrays of keys and frequencies, the algorithm should return the minimum possible weighted search cost of a binary search tree containing those keys.
Example:
- keys: [12, 10, 20, 42, 25, 37]
- frequencies: [8, 34, 50, 3, 40, 30]
- expected result: 324
Planned/implemented test coverage:
- empty input returns
0 - single key returns its frequency
- fixed small examples with known expected costs
- reference example with expected cost
324 - cross-check against a brute-force solver on small inputs
- invalid input handling:
- null arrays
- mismatched array lengths
- duplicate keys
- negative frequencies
Additional Information
No response
Reactions are currently unavailable