MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What does a bubble sort do?
A
Sorts a list by comparing two items that are side by side, to see which is out of order
B
Separates a list of data into different collections of data, before sorting and gathering back into a list
C
Finds an item of data in a list
D
None of the above
Explanation: 

Detailed explanation-1: -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-2: -Bubble Sort is one of the simplest sorting algorithms which works by repeatedly swapping the adjacent elements if they are in the wrong order. The logic of working-Greatest element of the list will be at the end after the 1st pass.

Detailed explanation-3: -The Bubble sort algorithm compares each pair of elements in an array and swaps them if they are out of order until the entire array is sorted. For each element in the list, the algorithm compares every pair of elements.

Detailed explanation-4: -Bubble sort is a type of sorting algorithm you can use to arrange a set of values in ascending order. If you want, you can also implement bubble sort to sort the values in descending order. A real-world example of a bubble sort algorithm is how the contact list on your phone is sorted in alphabetical order.

Detailed explanation-5: -Bubble sort starts with very first two elements, comparing them to check which one is greater. ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them.

There is 1 question to complete.