Data Structures & AlgorithmsHardGATE CS · Product placement
Selection sort (ascending; in pass i find the minimum of the unsorted part and swap it into position i only if it is not already there) is applied to [44, 58, 13, 30, 19, 25, 17, 11]. What is the array after 3 passes, and how many swaps will the complete sort make?
- A. [11, 13, 17, 30, 19, 25, 58, 44]; 7 swaps in total
- B. [13, 30, 44, 58, 19, 25, 17, 11]; 6 swaps in total
- C. [13, 19, 25, 17, 11, 30, 44, 58]; 6 swaps in total
- D. [11, 13, 17, 30, 19, 25, 58, 44]; 6 swaps in total
Correct answer: D. [11, 13, 17, 30, 19, 25, 58, 44]; 6 swaps in total
After 3 passes the 3 smallest values sit in front: [11, 13, 17, 30, 19, 25, 58, 44]. Over the whole sort, 6 passes find their minimum elsewhere and swap, so 6 swaps (at most n − 1).
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
- Only the lower triangle (including the diagonal) of a 12 × 12 matrix is stored row by row in a 1-D array B starting at B[0] (indices…
- Count palindromic substrings by expanding around all 2n − 1 centres, and also count DISTINCT palindromic substrings. What is printed?…
- You need to sort 10⁷ integers, each in the range 0 to 999. Which approach is asymptotically fastest?
- Count pairs with a given difference k (k > 0) among DISTINCT values using a hash set. What is printed? python a, k = [8, 7, 7, 10, 5, 11…
- Why is a tombstone (a 'deleted' marker) used instead of emptying a slot when deleting from an open-addressing hash table?
- Which statement about using a hash set versus sorting to detect duplicates in an array of n integers is correct?