How much time swapping of the given program when left child is smaller than the right child. void heapify(int a[], int n, int i) { int left = 2*i +…

How much time swapping of the given program when left child is smaller than the right child.

void heapify(int a[], int n, int i) {
    int left = 2*i + 1;
    int right = 2*i + 2;
    int smallest = i;
    if (left < n && a[left] < a[smallest])
        smallest = left;
    if (right < n && a[right] < a[smallest])
        smallest = right;
    if (smallest != i) {
        int temp = a[i];
        a[i] = a[smallest];
        a[smallest] = temp;
        heapify(a, n, smallest);
    }
}

From the BUET MSC (CSE) May 2019 – Written exam, question 4 of 16.

More from this paper