Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Quicksort uses the Lomuto partition with the last element as pivot on [99, 24, 44, 86, 76, 60, 84, 3]. After one partition call, at which index (0-based) does the pivot end up?
- A. 0
- B. 1
- C. 3
- D. 2
Correct answer: A. 0
The pivot 3 ends at index = count of elements <= 3 before it = 0. Array after partition: [3, 24, 44, 86, 76, 60, 84, 99].
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
- What is the time complexity of this code, as a function of n? c for (int i = 0; i < n; i++) for (int j = i; j < n; j++) sum += a[i] a[j];
- A sorted array is [1, 9, 9, 10, 13, 14, 18, 23, 23, 25]. Using the standard two-pointer in-place duplicate-removal technique (a slow…
- What is the time complexity of reading the element arr[i] from an array of n elements, given i?
- Which data structure works on the Last In, First Out (LIFO) principle?
- What is the worst-case time complexity of binary search on a sorted array of n elements?
- Which of these sorting algorithms is stable in its standard implementation?