The Gateway to Computer Science Excellence
0 votes
87 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 by Active (4.9k points) | 87 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.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,648 questions
56,429 answers
195,217 comments
99,950 users