
AFL 1 - part 2
Authored by Kasmir Syariati
Computers
University
Used 2+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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
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.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
20 questions
Spreadsheet Fundamentals - Quiz2
Quiz
•
University
20 questions
Processing- The CPU Quiz
Quiz
•
10th Grade - University
20 questions
Python Unit 1 Quiz
Quiz
•
University
20 questions
ASP.NET Core Basics (2)
Quiz
•
University
20 questions
DATASET'24 Quizz (Round 3)
Quiz
•
University
20 questions
IT Essential UIUX Chapter 03 (Typography)
Quiz
•
University
20 questions
Video
Quiz
•
University
20 questions
Skill Competition Quiz 2024
Quiz
•
10th Grade - University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
10 questions
Probability Practice
Quiz
•
4th Grade
15 questions
Probability on Number LIne
Quiz
•
4th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
6 questions
Appropriate Chromebook Usage
Lesson
•
7th Grade
10 questions
Greek Bases tele and phon
Quiz
•
6th - 8th Grade
Discover more resources for Computers
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
20 questions
Endocrine System
Quiz
•
University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
30 questions
W25: PSYCH 250 - Exam 2 Practice
Quiz
•
University
5 questions
Inherited and Acquired Traits of Animals
Interactive video
•
4th Grade - University
20 questions
Implicit vs. Explicit
Quiz
•
6th Grade - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University
38 questions
Unit 8 Review - Absolutism & Revolution
Quiz
•
10th Grade - University