MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The following list is to be sorted using a bubble sort:12 6 8 1 3What will the list look like after the first iteration through the list?
A
6 8 1 3 12
B
6 12 1 8 3
C
1 3 6 8 12
D
6 8 1 12 3
Explanation: 

Detailed explanation-1: -The algorithm will only recognise that the list is in order if it makes no changes in a pass. The algorithm therefore needs to run for a third pass to compare the numbers again. As no changes will be made, the algorithm will then recognise that the data is in order.

Detailed explanation-2: -We know that to sort a list of n elements using bubble sort, we need to perform n – 1 iterations.

Detailed explanation-3: -The algorithm needs one whole pass without any swap to know it is sorted.

Detailed explanation-4: -How many iterations will be done to sort the array? Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations to sort the given array.

There is 1 question to complete.