MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many passes will a bubble sort go through?
A
Only one pass
B
Two passes
C
Several passe-until the data is fully ordered
D
None of the above
Explanation: 

Detailed explanation-1: -Three passes will be required; First Pass. ( 5 1 4 2 8 ) → ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.

Detailed explanation-2: -Answer: N-1 passes, N-number of elements.

Detailed explanation-3: -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-4: -The algorithm for bubble sort requires a pair of nested loops. The outer loop must iterate once for each element in the data set (of size n) while the inner loop iterates n times the first time it is entered, n-1 times the second, and so on.

There is 1 question to complete.