Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Insertion sort in place

Q164·Free·SystemVerilog

Insertion sort in place

Difficulty
Easy
Topic
Arrays
Language
SV
Interview prompt

Question

Sort a dynamic array of integers in ascending order using insertion sort.

Candidate starting point

Implementation scaffold

function automatic void insertion_sort(ref int values[]);
  // TODO: implement.
endfunction
Reviewed example

Trace one case

Input
values = [5, 1, 4, 2]
Expected output
[1, 2, 4, 5]

Each element is inserted into the already sorted prefix while equal elements retain their order.

What to cover

Requirements

  1. Modify the input array in place.
  2. Keep equal values in their original relative order.
  3. Handle negative values and duplicate values.
Exact question handoffPractice Q164

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

Firmware Guide

Review algorithms, data structures, fixed-memory reasoning, concurrency, and silicon bring-up.

  • Arrays
  • Sorting
  • Dynamic array
  • Stable
Firmware Guide →
Continue practicing

Related questions

Q1079 · ArraysBubble sort in placeEasyP→Q207 · ArraysQuicksort a dynamic arrayMediumP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi