Computer Science EngineeringHardISRO SC (CS)
Insertion sort (scanning the sorted prefix from right to left, stopping at the first element not greater than the key) is run on [9, 7, 19, 36, 31, 34, 18, 23]. The number of key comparisons is:
- A. 10
- B. 18
- C. 17
- D. 16
Correct answer: D. 16
Comparisons = inversions + (number of keys that stop at an element, i.e. those with a smaller element to their left) = 16; inversions alone = 10.
Practise more Algorithms, Data Structures & Programming (ISRO CS) questionsAlgorithms, Data Structures & Programming (ISRO CS): notes and key points
More Algorithms, Data Structures & Programming (ISRO CS) questions
- Consider the following C fragment. int c=0; int x=40; while(x>0){ for(int j=0;j<x;j++) c++; x/=3; } What is c at the end? (integer division)
- Tower of Hanoi with 10 disks and three pegs needs the minimum number of moves equal to:
- Which data structure follows the Last-In-First-Out principle?
- The height (in edges) of a complete binary tree having n nodes is
- The time needed to build a binary heap from n arbitrary elements using bottom-up heapify is
- The maximum number of nodes in a binary tree of height h (root at height 0) is