MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Why does a bubble sort do a final pass even when the data is in the correct order?
A
To save the data
B
It does not recognise that the data is in order until the final pass requires no changes
C
It needs to do this to put the data back in to a list
D
None of the above
Explanation: 

Detailed explanation-1: -With a bubble sort, it is always necessary to make one final “pass” through the array to check to see that no swaps are made to ensure that the process is finished. In actuality, the process is finished before this last pass is made.

Detailed explanation-2: -A bubble sort algorithm goes through a list of data a number of times, comparing two items that are side by side to see which is out of order. It will keep going through the list of data until all the data is sorted into order. Each time the algorithm goes through the list it is called a ‘pass’.

Detailed explanation-3: -First pass If the first card has a higher value, the cards are swapped. In this example, the value 9 is compared to the value 3; 9 is higher than 3 so the cards are swapped. The second card is then compared to the third, and swapped if its value is higher.

Detailed explanation-4: -In a bubble sort algorithm to be sorted in ascending order, after the first pass, the first element will hold the lowest value. One problem with the bubble sort is that it is limited to arranging data only in ascending order. Sort algorithms can only be used on arrays that hold numeric values.

There is 1 question to complete.