Open In App

Top | MCQs on BubbleSort Algorithm with Answers | Question 8

Last Updated : 02 Aug, 2023
Like Article
Like
Save
Share
Report

Bubble Sort is an example of a sorting algorithm that:

(A)

Uses divide and conquer strategy

(B)

Uses dynamic programming

(C)

Swaps adjacent elements directly

(D)

Only works with integers


Answer: (C)

Explanation:

Bubble Sort is an example of a sorting algorithm that Swaps adjacent elements directly

void bubbleSort(int arr[], int n)
{
    int i, j;
    bool swapped;
    for (i = 0; i < n - 1; i++) {
        swapped = false;
        for (j = 0; j < n - i - 1; j++) {
        
        //swap adjacent directly
            if (arr[j] > arr[j + 1]) {
                swap(&arr[j], &arr[j + 1]);
                swapped = true;
            }
        }
        if (swapped == false)
            break;
    }
}

Hence (C) is the correct answer.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads