menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Sorting al...
source image

Prodevelopertutorial

3w

read

373

img
dot

Sorting algorithm 1: Bubble sort

  • Bubble sort is a sorting algorithm which swaps two elements if the next element is greater in value.
  • Bubble sort involves two loops, an outer and an inner one.
  • In bubble sort, the largest element is sorted and brought to the end of the list in every iteration.
  • An implementation of bubble sort in C is provided to sort an array by comparing and swapping elements.
  • Bubble sort has a time complexity of O(n^2) as it always compares two elements in each pass.
  • Bubble sort sorts an array by making comparisons between two adjacent values and swapping them whenever required.
  • The sorted array can be displayed with the 'print_array' function.
  • Bubble sort is commonly used in small-scale applications and not as much in larger real-time applications.
  • The program saves processing time by breaking out of the loop if no swapping is done after the third pass.
  • Bubble sort is not considered an efficient sorting algorithm for large arrays.

Read Full Article

like

22 Likes

For uninterrupted reading, download the app