Data Structures & AlgorithmsModerateIBM · Deloitte pattern
How many element shifts does insertion sort perform to sort [4, 3, 2, 10, 12, 1, 5, 6] in ascending order?
- A. 12
- B. 13
- C. 8
- D. 15
Correct answer: A. 12
Each shift fixes exactly one inversion, so shifts = number of inversions = 3 (from 4) + 2 (from 3) + 1 (from 2) + 3 (from 10) + 3 (from 12) = 12. 8 is the number of elements, not of shifts.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Quick sort with the Lomuto partition (pivot = last element) is run on an already sorted array of 10 distinct elements. How many…
- Binary search (one three-way comparison per probe) is done on a sorted array of 1000 elements. What is the maximum number of probes needed?
- This code tries to reverse the singly linked list 1 → 2 → 3 → 4, but its last line has been changed from cur = nxt. What does the list…
- A linked list has 3 nodes before the loop starts and a loop of 5 nodes. Floyd's slow pointer moves 1 step and fast pointer 2 steps per…
- ^ is exponentiation (highest precedence, right-associative). What is the postfix form of A + B C ^ D ^ E − F?
- What is the value of the postfix expression 2 3 2 ^ ^ (^ means power)?