Consider an array $A=[10,7,8,19,41,35,25,31]$. Suppose the merge sort algorithm is executed on array $A$ to sort it in increasing order. The merge sort algorithm will carry out a total of 7 merge operations.
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)
$$\text { 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[]]>A[j + 1])
then swap A[j] and A[j+1]
}
Let $A[0, \ldots, 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 $A[0, \ldots, 29]$ as argument, is _________. (Answer in integer)
Let $A$ be an array containing integer values. The distance of $A$ is defined as the minimum number of elements in $A$ that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2, 5, 3, 1, 4, 2, 6] is __________
Consider the following array.
|
23 |
32 |
45 |
69 |
72 |
73 |
89 |
97 |
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort above array in ascending order?
GATE CSE Subjects
Browse all chapters by subject