An array has 5 elements. Calculate the following:
SL. NO:
NAME
ARRAY IS ALREADY SORTED
ARRAY IS REVERSE SORTED
ELEMENT COMPARSIONS
ELEMENT EXCHANGES
ELEMENT COMPARISONS
1
BUBBLE SORT
?
2
SELECTION SORT
3
INSERTION SORT
4
QUICK SORT
5
MERGE SORT
6
RADIX SORT
7
HEAP SORT
8
TREE SORT
9
COUNTING SORT
Assuming this is the code for selection sort:
for(i=0;i<n-1;i++){ smallest=a[i]; for(j=i+1;j<n;j++){ if(smallest>a[j]) smallest=a[j]; } if(smallest!=a[i]) a[i]=smallest; }
(4+1) + (3+1) + (2+1) = 12
0
(assuming all elements are consecutive)
64.3k questions
77.9k answers
244k comments
80.0k users