Contents
Page-10
Prev
Next
Page+10
Index
Merge Technique
The merge technique can be used to perform a variety of operations on
sequences of items (linked lists or arrays) in O(n · log(n)) time:
- Sort both sequences: O(n · log(n))
- The merging function steps through the sequences one element at a time,
looking only at the two front elements and comparing their keys.
- The function performs some operation involving one or both
front elements, perhaps producing some output.
- The function may step down one list, the other list, or both lists.
- Examples: merge two sorted lists in order; set intersection, union,
or set difference; update a bank account based on a transaction.