Vidyalelo
Data Structure · all questions

Sorting Algorithms
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

509

Questions

9/26

Page

Pick an option on a question to see the right answer and solution.

Choose the correct option to fill? X so that the code given below implements the Heap sort.
#include <stdio.h> 
void heapify(int arr[], int n, int i) 
{ 
    int largest = i; // Initialize largest as root 
    int l = 2*i + 1; // left = 2*i + 1 
    int r = 2*i + 2; // right = 2*i + 2 
    if (l < n && arr[l] > arr[largest]) 
        largest = l; 
    if (r < n && arr[r] > arr[largest]) 
        largest = r; 
    if (largest != i) 
    { 
        swap(arr[i], arr[largest]); 
        heapify(arr, n, largest); 
    } 
} 
void heapSort(int arr[], int n) 
{ 
    for (int i = n / 2 - 1; i >= 0; i--) 
        heapify(arr, n, i); 
    for (int i=n-1; i>=0; i--) 
    { 
        X;
        heapify(arr, i, 0); 
    } 
} 
void printArray(int arr[], int n) 
{ 
    for (int i=0; i<n; ++i) 
        printf(“%d”,arr[i]);
    printf(“\n”);	    
} 
int main() 
{ 
    int arr[] = {12, 11, 13, 5, 6, 7}; 
    int n = sizeof(arr)/sizeof(arr[0]); 
    heapSort(arr, n); 
    printf(“Sorted array is \n"); 
    printArray(arr, n); 
}

Select an option to see the answer and solution.

What is the auxiliary space requirement of Tim sort?

Select an option to see the answer and solution.

What is the best case time complexity of strand sort?

Select an option to see the answer and solution.

Which of the following is not an adaptive sorting algorithm?

Select an option to see the answer and solution.

Which of the following is true for the LSD radix sort?

Select an option to see the answer and solution.

What is the worst case time complexity of Tim sort?

Select an option to see the answer and solution.

Cocktail sort is a variation of . . . . . . . .

Select an option to see the answer and solution.

Which of the following sorting algorithm is used by C++ internally?

Select an option to see the answer and solution.

Which of the following sorting algorithm uses the method of insertion?

Select an option to see the answer and solution.

If Hibbard increments (h1 = 1, h2 = 3, h3 = 7, ..., hk = 2k - 1) are used in a Shell sort implementation, then the best case time complexity will be . . . . . . . .

Select an option to see the answer and solution.

What is the best case time complexity of the binary tree sort?

Select an option to see the answer and solution.

What is the advantage of library sort over insertion sort?

Select an option to see the answer and solution.

What is the worst case complexity of bubble sort?

Select an option to see the answer and solution.

What is the auxiliary space complexity of randomized quick sort?

Select an option to see the answer and solution.

What is the best case time complexity of recursive bubble sort?

Select an option to see the answer and solution.

On how many increment sequences does the worst case analysis of shell sort depends?

Select an option to see the answer and solution.

What is the advantage of radix sort over quick sort?

Select an option to see the answer and solution.

Binary tree sort is an in-place sorting algorithm.

Select an option to see the answer and solution.

In which of the following case strand sort is most efficient?

Select an option to see the answer and solution.

What is the best case time complexity of cube sort?

Select an option to see the answer and solution.