• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 2 pages
Exam (elaborations)

Elementary Sorting: Bubble, Selection and Insertion – Data Structures and Algorithms: Exam-Ready Questions and Answers

Document preview thumbnail
Preview 1 out of 2 pages

Elementary Sorting: Bubble, Selection and Insertion – Data Structures and Algorithms: Exam-Ready Questions and Answers

Content preview

Elementary Sorting: Bubble, Selection and
Insertion – Data Structures and Algorithms:
Exam-Ready Questions and Answers
LATEST UPDATE 2026/2027 | PREMIUM ACADEMIC EDITION

Exam 09 of 40 | Unit code: DSA-09 | Questions: 6 | Total marks: 30 | Answer ALL questions


Question 1: [5 marks]
Explain bubble sort, including the optimization that lets it finish early, and state its
complexities.

Answer:

Bubble sort repeatedly compares adjacent elements and swaps them if they are out of order;
after each pass the largest remaining element is at the end. If a full pass makes no swap, the
array is sorted and the algorithm stops early.
Worst and average case O(n2); best case O(n) with the early-exit flag; space O(1); stable.


Question 2: [4 marks]
Show the result of the first pass of bubble sort on [5, 1, 4, 2, 8].

Answer:

Compare 5 and 1: swap → [1, 5, 4, 2, 8]. Compare 5 and 4: swap → [1, 4, 5, 2, 8]. Compare 5 and
2: swap → [1, 4, 2, 5, 8]. Compare 5 and 8: no swap.
After pass 1: [1, 4, 2, 5, 8].


Question 3: [5 marks]
Describe selection sort and state its complexities.

Answer:

Selection sort repeatedly finds the minimum of the unsorted part and swaps it into the next
position of the sorted part. It makes n(n − 1)/2 comparisons in every case, so its time is always
2
O(n ), with at most n − 1 swaps and O(1) space. The usual version is not stable.


Question 4: [5 marks]
Describe insertion sort. When is it a good choice?

Answer:

Insertion sort builds a sorted prefix: each new element is compared with the sorted elements on
its left and shifted into its correct position. Best case O(n) (already sorted), average and worst
2
case O(n ), space O(1), stable.
It is a good choice for small arrays and for nearly sorted data, and is often used inside hybrid
algorithms.




Page 1 Data Structures and Algorithms • Exam 09

Document information

Uploaded on
November 9, 2026
Number of pages
2
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$13.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
413
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions