Home / MCQ Bank / Computer
Computer Sorting Algorithms Difficulty: Medium

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 the correct option to test your answer:

More Computer Questions

Which header file is used to define data formats and currency symbols? What will be the output of the following C++ code? #include <iostream> using namespace std; class Cat { public: int age; int weight; }; int main() { Cat f; f.age = 56; cout << "Gates is " ; cout << f.age << " years old.\n"; } What was the base of first generation computer systems? Which object is the top of the hierarchy? In Python, which module provides functions for working with dates and times?