search
Log In
0 votes
270 views

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

ELEMENT EXCHANGES

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

?

?

?

?

 
in Algorithms 270 views
0
Assume all 5 elements are distinct
0
is it need time complexity?
0
Number of Comparisons and Number of Exchanges
0
upto where you solved?
0
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;
}

SL. NO:

NAME

ARRAY IS ALREADY SORTED

ARRAY IS REVERSE SORTED

ELEMENT COMPARSIONS

ELEMENT EXCHANGES

ELEMENT COMPARISONS

ELEMENT EXCHANGES

1

BUBBLE SORT

4 0 4+3+2+1 = 10 4+3+2+1 = 10

2

SELECTION SORT

(4+1) + (3+1) + (2+1) = 12

0

(4+1) + (3+1) + (2+1) = 12

4

3

INSERTION SORT

4

0

?

?

4

QUICK SORT

?

?

?

?

5

MERGE SORT

6

0

6

0

6

RADIX SORT

(assuming all elements are consecutive) 

0

0

0 0

7

HEAP SORT

?

?

?

?

8

TREE SORT

?

?

?

?

9

COUNTING SORT

0 0

0

 

0

 

 

 

 

Please log in or register to answer this question.

Related questions

0 votes
0 answers
1
98 views asked Oct 23, 2018 in Algorithms Balaji Jegan 98 views
0 votes
1 answer
2
71 views
Suppose f, g, h, k : N → N. If f = O(h) and g = O(k), then 1) f + g = O(h + k) 2) fg = O(hk) 3) Both 1 and 2 4) None of the above
asked Oct 24, 2018 in Algorithms Balaji Jegan 71 views
0 votes
2 answers
3
223 views
A man alternately tosses a coin and throws a dice, beginning with the coin. Then probability that he will get a head before he gets a 5 or 6 on dice is 1) 1/4 2) 3/4 3) 4/5 4) 4/7
asked Oct 24, 2018 in Probability Balaji Jegan 223 views
0 votes
1 answer
4
65 views
If mean = (3 median – mode)x, then value of x is 1) 1 2) 2 3) 1/2 4) 3/2
asked Oct 24, 2018 in Probability Balaji Jegan 65 views
...