- Merge Sort
- Selection Sort
- Heap Sort
Explanation:
The correct answer is option (c).
Selection sort is generally more effective than Bubble Sort because fewer comparisons are required, and the average number of swaps is half. Though, both algorithms have quadratic time complexity O(n^2).
- What will happen if you run Bubble Sort on a linked list?
- It runs equally as on an array.
- It runs worse because of a lot of pointer updates.
- It runs faster than on an array.
- It can't be run on a linked list.
Explanation:
The correct answer is option (b).
The poor performance of Bubble Sort in a linked list is due to the frequent update of pointers in the process of swapping.
- Why is Bubble Sort not suitable for large datasets?
- Because it uses too much memory.
- Because it has a high time complexity.
- Because it is difficult to implement.
- Because it is not a comparison-based sort.
Explanation:
The correct answer is option (b).
Accordingly, Bubble Sort is not suitable due to its high time complexity of O(n^2) on huge datasets.
- How does the stability of Bubble Sort affect its performance on certain datasets?
- It does not affect performance.
- It improves performance on large datasets.
- It maintains the relative order of equal elements.
- It increases the time complexity.
Explanation:
The correct answer is option (c).
The reliability of Bubble Sort lies in its ability to uphold the sequence of identical elements, which proves advantageous for datasets containing duplicates.
- What is the purpose of the code snippet below?
void bubblesort(int arr[], int n)
{
int i,j, temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(arr[j]<arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
- Sorts the array in ascending order
- Sorts the array in descending order
- Finds the maximum element
- Finds the minimum element
Explanation:
The correct answer is option (b).
This version of Bubble Sort organizes the array in a descending sequence by swapping elements when the current element has a lesser value than the following element.