A merge operation on sorted left array $L$ and sorted right array $R$ is said to be void if the output of the merge operation is the elements of array $L$ followed by the elements of array $R$.
The number of void merge operations among these 7 merge operations is __________. (answer in integer)
The question asks for the number of "void" merge operations performed during the merge sort of the array $A = [10, 7, 8, 19, 41, 35, 25, 31]$. A merge operation is defined as "void" if the elements from the left sorted array ($L$) appear entirely before the elements from the right sorted array ($R$) in the merged output. This occurs when every element in $L$ is less than or equal to every element in $R$.
We trace the merge sort process step-by-step:
We check the condition for a void merge for each operation:
Counting the void merge operations identified above:
Therefore, there are a total of 3 void merge operations.
What is the worst case time complexity of bubble sort?
The pseudocode of a function fun() is given below:
fun(int A[0, …, n-1]) {
for i = 0 to n - 2
for j = 0 to n - i - 2
if (A[j] > A[j + 1])
then swap A[j] and A[j + 1]
}
Let 𝐴[0, … ,29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with 𝐴[0, … ,29] as argument, is __________. (Answer in integer)
Any decision tree that sorts n elements has height
You have to sort a list L, consisting of a sorted list followed by a few ‘random’ elements. Which of the following sorting method would be most suitable for such a task ?
If there are n integers to sort, each integer has d digits and each digit is in the set {1, 2, ..., k}, radix sort can sort the numbers in :