Question: 3. [13 marks] Given the following sorting methods: template void sort(Elem A[], int n) { for (int i=0; i int lowindex = i; for (int

3.

[13 marks]

Given the following sorting methods:

template

void sort(Elem A[], int n) {

for (int i=0; i

int lowindex = i;

for (int j=n-1; j>i; j--)

if ((A[j]

if (lowindex != i) swap(A, i, lowindex);

}

}

a)

What is the name of the given function sort()?

(2 marks)

b)

Given the unsorted list: 12, 4, 16, 8 and 20. By using the given sorting methods, write down

the result of each iteration of outer for loop:

(7 marks)

i=0

i=1

i=2

i=3

12

4

4

8

16

12

8

16

20

20

c)

Describe a sorting method which has a smaller Big-O than sort() in detail.

(4 marks)

3. [13 marks] Given the following sorting methods: template void sort(Elem A[],

3. [13 marks Given the following sorting methods: template void sort (Elem A[], int n) { for (int i=0; ii; j--) if ((A[j]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!