• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 1 fuera de 2 páginas
Examen

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

Document preview thumbnail
Vista previa 1 fuera de 2 páginas

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

Vista previa del contenido

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

Información del documento

Subido en
9 de noviembre de 2026
Número de páginas
2
Escrito en
2026/2027
Tipo
Examen
Contiene
Preguntas y respuestas
$13.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
237
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes