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?

AFL 1 - part 2

Quiz
•
Computers
•
University
•
Medium
Kasmir Syariati
Used 1+ times
FREE Resource
24 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
n(n – 1)/2
n(n – 1)/2 + (n – 1)
n²/2
n²
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)²
n²
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
Similar Resources on Quizizz
29 questions
CSC 105 ACTIVITY

Quiz
•
University
20 questions
Algo Duel

Quiz
•
University
20 questions
TECHNICAL QUIZ

Quiz
•
University
19 questions
Prog1 A&D Quiz

Quiz
•
University
20 questions
Sorting and Searching Algorithms Quiz - Batch 1

Quiz
•
University
20 questions
Quantitative Aptitude Series

Quiz
•
University
20 questions
SMARTICUS

Quiz
•
University
23 questions
Data Structures and Algorithms Quiz - BATCH 1

Quiz
•
University
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade