The Process of Arrangement of Data in Ascending or Descending Order Is Called Sorting
The document discusses three sorting algorithms: bubble sort, selection sort, and insertion sort. Bubble sort works by comparing adjacent elements and swapping them if out of order until the largest/smallest element reaches the end. Selection sort finds the minimum element and exchanges it into the first position, then finds the next minimum and exchanges it, continuing until fully sorted. Insertion sort shifts elements one by one, comparing a key to elements ahead and inserting it into the right place.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
33 views9 pages
The Process of Arrangement of Data in Ascending or Descending Order Is Called Sorting
The document discusses three sorting algorithms: bubble sort, selection sort, and insertion sort. Bubble sort works by comparing adjacent elements and swapping them if out of order until the largest/smallest element reaches the end. Selection sort finds the minimum element and exchanges it into the first position, then finds the next minimum and exchanges it, continuing until fully sorted. Insertion sort shifts elements one by one, comparing a key to elements ahead and inserting it into the right place.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9
Sorting
• The Process of Arrangement of data in ascending or
descending order is called sorting. • Types of Sorting: 1) Bubble Sorting 2) Selection Sorting 3) Insertion Sorting Bubble Sorting bubble-sort is one of the simplest algorithms. The bubble- sort algorithm makes various passes over a one-dimensional array. For each pass, that algorithm compares adjacent data items to determine which is numerically larger or smaller. Either the larger data item (for ascending order) or the smaller data item (for descending order) swaps with the adjacent data item and moves toward the bottom of the one-dimensional array. By the end of the pass, the largest/smallest data item has moved toward the array's end. Continuous… Bubble Sort Algorithm DECLARE INTEGER i, pass DECLARE INTEGER x [] = [ 20, 15, 12, 30, -5, 72, 456 ] FOR pass = 0 TO LENGTH (x) - 2 FOR i = 0 TO LENGTH (x) - pass - 2 IF x [i] > x [i + 1] THEN SWAP x [i], x [i + 1] END IF NEXT i NEXT pass END Selection Sort
Selection sorting is conceptually the most simplest sorting
algorithm. The algorithm first find the smallest element in the array and exchanges it with the element in the first position, then find the second smallest element and exchange it with the element in the second position. And continues in this way until the entire array is sorted. Continuous… Selection Sort Algorithm SelectionSort( A , 6 ) { for i 0 to n – 2 { iMin i For j i + 1 to n – 1 { If ( A [ j ] < A [ iMin ] ( iMin j } temp = A [ i ] A [ i ] = A [ iMin ] A[ iMin ] = temp } { Insertion Sort
It is a simple algorithm which sort the array by shifting element
one by one.
In insertion sort we pick up a key, and compare it with elements
ahead of it and put the key in the right place. Continuous…