Identify the algorithm used in the following code.

void algo(int arr[], int n){
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++){
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}

a. Bubble sort, O(n^2)
b. Insertion sort, O(n^2)
c. Merge sort, O(n log n)
d. Quick sort, O(n log n)

a. Bubble sort, O(n^2)

Computer Science & Information Technology

You might also like to view...

Reports can include charts

Indicate whether the statement is true or false

Computer Science & Information Technology

Increasing the font size while in Print Preview by using the zoom increases the actual font size of the document when printed

Indicate whether the statement is true or false

Computer Science & Information Technology