Q: What is the time complexity of a merge sort algorithm for sorting an array of n elements in the worst case?
-
A
O(1)
-
B
O(log n)
-
C
O(n)
-
D
O(n log n)
D
Answer:
D
Explanation:
Merge sort is a divide-and-conquer sorting algorithm that divides the array into smaller subarrays, recursively sorts them, and merges them to obtain the sorted array. In each recursion, the array is divided in half, resulting in a logarithmic number of levels. At each level, the merge operation combines two sorted subarrays, which takes linear time. Therefore, the time complexity of merge sort in the worst case is O(n log n).
Related Topic:
Share Above MCQ