











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Sorting
Bubble Sort
Bubble Sort
Bubble Sort void bubbleSort( int arr[], int size) { int temp = 0; for ( int i=0; i < size; i++) { for ( int j = size-1; j>i; j--) { if (arr[j] < arr[j-1] ) { temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; } } } }
Bubble Sort
SELECTION SORT
Selection Sort
Complexity of Selection Sort
Selection Sort void selectionSort( int arr[], int size) { for ( int i=0; i < size; i++) { int min = i; for ( int j=i+1; j < size; j++) if (arr[j] < arr[min]) min = j; if (min != i) { int temp = arr[i]; arr[i] = arr[min]; arr[min] = temp; } } }
Insertion Sort
Insertion Sort
Insertion Sort void insertionSort( int arr[], int size) { for ( int i=1; i < size; i++) { int value = arr[i]; for ( int j = i-1; j >= 0 && arr[j] > value; j--) arr[j+1] = arr[j]; arr[j+1] = value; } }