MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Compares pairs of items and swaps them if they are in the wrong order. Each pair in the list is checked.
A
Bubble sort
B
Insertion sort
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -Bubble sort is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

Detailed explanation-2: -In ascending order: In Bubble sort, the largest element moves to the right. So swapping is done, when a smaller element is found on the right side. So to count the number of swaps for an element, just count the number of elements on the right side that are smaller than it.

Detailed explanation-3: -Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.

Detailed explanation-4: -Bubble sort repeatedly passes through an unsorted list, comparing pairs of neighbouring elements and swaps them if they are not in the right order, until no swaps occur, this indicates the list is now sorted.

There is 1 question to complete.