A list of strings, each of length , is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
View worked solution
Answer: B
To find the worst-case running time of sorting strings, each of length , using merge-sort, we analyze the two main operations performed during the algorithm: string comparisons and string copying.
1. Comparison Cost:
- Standard merge-sort on elements requires comparisons in the worst case.
- Comparing two strings of length lexicographically takes time in the worst case (since we may need to compare up to all characters).
- Therefore, the total time spent on comparisons is:
2. Copying Cost:
- At each of the levels of the merge-sort recursion tree, all strings are copied into auxiliary arrays during the merge step.
- Copying a single string of length takes time.
- Thus, the copying cost at each level is .
- Across all levels, the total copying time is:
Combining both costs, the overall worst-case running time is .
Hence, the correct option is (B).
Free practice · Your answers on this page are not saved.
