AFL 1 - part 2

AFL 1 - part 2

University

24 Qs

quiz-placeholder

Similar activities

C - Data Structures (Unit 1 - QUIZ)

C - Data Structures (Unit 1 - QUIZ)

University

25 Qs

DSA QUIZ

DSA QUIZ

University

20 Qs

DS QUIZ 2

DS QUIZ 2

University

20 Qs

Team 4 Data structure

Team 4 Data structure

University

20 Qs

CA mcq

CA mcq

University

25 Qs

Data Structures Quiz

Data Structures Quiz

University

20 Qs

Algorithm Analysis

Algorithm Analysis

University

21 Qs

3ICTH7H8DSA

3ICTH7H8DSA

University

25 Qs

AFL 1 - part 2

AFL 1 - part 2

Assessment

Quiz

Computers

University

Medium

Created by

Kasmir Syariati

Used 1+ times

FREE Resource

24 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider Insertion Sort applied to an array of n distinct elements. In the worst-case scenario (i.e., the array is reverse sorted), what is the exact total number of comparisons performed?

n(n – 1)/2

n(n – 1)/2 + (n – 1)

n²/2

Answer explanation

In the worst-case, the inner loop of Insertion Sort makes 1 comparison for the 2nd element, 2 for the 3rd, and so on up to n–1 comparisons for the last element. Summing these gives 1 + 2 + … + (n – 1) = n(n – 1)/2 comparisons.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Regardless of the initial order of the elements, what is the exact number of comparisons performed by Selection Sort when sorting an array of n elements?

n(n + 1)/2

n(n – 1)/2

(n – 1)²

Answer explanation

In Selection Sort, the algorithm scans the unsorted portion for each of the n–1 positions. The first pass makes (n – 1) comparisons, the second makes (n – 2), and so on. The total is (n – 1) + (n – 2) + … + 1 = n(n – 1)/2, regardless of input order.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which algorithm shows adaptive behavior that significantly reduces the number of comparisons on nearly sorted input, and why?

Insertion Sort, because it quickly detects that few or no shifts are needed.

Selection Sort, because it avoids scanning the entire unsorted segment.

Insertion Sort, because its number of swaps is always minimal.

Selection Sort, because it makes fewer comparisons when the array is nearly sorted.

Answer explanation

Insertion Sort benefits from nearly sorted input because its inner loop terminates early when the current element is already in the correct position, resulting in O(n) time in the best-case scenario. In contrast, Selection Sort always makes the same number of comparisons.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In terms of write operations, which algorithm is typically more efficient, and what is the maximum number of swaps (or writes) it performs on an array of n elements?

Insertion Sort, with up to n(n – 1)/2 writes

Selection Sort, with up to n – 1 writes

Insertion Sort, with up to n – 1 writes

Selection Sort, with up to n(n – 1)/2 writes

Answer explanation

Standard Selection Sort makes one swap per outer loop iteration (if a swap is needed), for a maximum of n – 1 swaps. Insertion Sort, particularly a swap-based implementation, may require far more writes due to repeated swapping, making Selection Sort more write-efficient when writes are expensive.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Both Insertion Sort and Selection Sort are considered in-place algorithms. What is their extra space complexity, and what does this imply about additional memory usage?

O(n), meaning they require additional memory proportional to the input size

O(1), meaning they use only a constant amount of extra memory

O(log n), due to recursion overhead in Insertion Sort

O(n²), since they create auxiliary matrices

Answer explanation

Both algorithms rearrange the input array without needing extra data structures (beyond a few temporary variables), so their extra space complexity is O(1).

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

For Insertion Sort, the average-case number of comparisons on an array of n distinct elements is approximately:

n(n – 1)/2

n²/4

n log n

n/2

Answer explanation

A probabilistic analysis shows that, on average, Insertion Sort performs about n²/4 comparisons. This result comes from averaging the cost of inserting each element into the sorted portion.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Stability is a critical property in sorting when elements have secondary keys. Which of the following is true regarding stability for the two algorithms in their standard implementations?

Both Insertion Sort and Selection Sort are stable by default.

Insertion Sort is stable by default, while Selection Sort is not stable unless modified.

Selection Sort is stable by default, while Insertion Sort is not.

Neither is stable, and both require additional mechanisms to ensure stability.

Answer explanation

Insertion Sort is inherently stable because it inserts elements without disrupting the relative order of equal items. Standard Selection Sort, however, may swap non-adjacent elements and thus is not stable without modifications.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?