Question:

__________ compares neighboring elements only and swaps them when necessary?

Updated On: Mar 29, 2025
  • Selection Sort
  • Bubble Sort
  • Insertion Sort
  • Quick Sort
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

(1) Selection Sort: Selection sort finds the minimum element in the unsorted portion and places it at the beginning. It does not compare neighboring elements and swap them repeatedly.

(2) Bubble Sort: Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. This process bubbles the largest element to the end of the array in each pass.

(3) Insertion Sort: Insertion sort iterates through the array and inserts each element into its correct position in the sorted portion. It shifts elements as needed, but its primary operation is not solely comparing and swapping neighbors.

(4) Quick Sort: Quick sort is a divide-and-conquer algorithm that selects a pivot element and partitions the array around it. While there are comparisons and potentially swaps involved in partitioning, it doesn't only compare and swap neighboring elements.

Therefore, the algorithm that compares neighboring elements and swaps them when necessary is (2) Bubble Sort.

Was this answer helpful?
0
0