Skip to content
StackDecode
GreedyExplained

Optimal Merge Pattern

Always merge the two smallest files.

Time

O(n log n)

Extra space

O(n)

Use it for

Minimising merge cost.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.