Unit 6: Efficient Sorting Algorithms & Analysis - Practice Quiz

CSE330 — Competitive Coding Approaches-Techniques 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which sorting algorithm commonly has an average time complexity of ?

Introduction to O(n logn) Sorting Algorithms Easy
A. Merge sort
B. Linear search
C. Sequential scan
D. Bubble sort

2 What does usually represent in the complexity ?

Introduction to O(n logn) Sorting Algorithms Easy
A. Array value
B. Memory address
C. Number of elements
D. Number of swaps

3 Which of the following is an efficient comparison-based sorting algorithm?

Introduction to O(n logn) Sorting Algorithms Easy
A. Insertion sort
B. Selection sort
C. Bubble sort
D. Merge sort

4 What is the main operation performed during the merge step of merge sort?

Iterative & Recursive Merge Sort Easy
A. Reversing the array
B. Choosing a random pivot
C. Combining sorted parts
D. Counting duplicate values

5 What is the base case in a recursive merge sort implementation?

Iterative & Recursive Merge Sort Easy
A. A reversed array
B. A full unsorted array
C. An array with duplicates
D. A one-element array

6 How does recursive merge sort divide an array?

Iterative & Recursive Merge Sort Easy
A. Into equal values
B. Into random groups
C. Into odd positions
D. Into two halves

7 Which type of merge sort avoids recursive function calls?

Iterative & Recursive Merge Sort Easy
A. Pivot merge sort
B. Frequency merge sort
C. Randomized merge sort
D. Iterative merge sort

8 What is the purpose of a pivot in quick sort?

Quick Sort Easy
A. To count all elements
B. To store duplicate values
C. To reverse the input
D. To partition the array

9 What is the average time complexity of quick sort?

Quick Sort Easy
A.
B.
C.
D.

10 What can happen when quick sort repeatedly selects a poor pivot?

Quick Sort Easy
A. Time can become
B. The algorithm becomes a merge sort
C. Time always becomes
D. The array becomes sorted instantly

11 After partitioning around a pivot, where are smaller elements generally placed?

Quick Sort Easy
A. After the pivot
B. Outside the array
C. Before the pivot
D. In a separate queue

12 When sorting elements by frequency, what is counted first?

Sorting Elements by Frequency Easy
A. Positions of each value
B. Length of each value
C. Occurrences of each value
D. Indexes of the array

13 In frequency-based sorting, which value usually appears first when sorting by decreasing frequency?

Sorting Elements by Frequency Easy
A. First input value
B. Largest index
C. Most frequent value
D. Smallest index

14 What data structure is commonly used to store element frequencies?

Sorting Elements by Frequency Easy
A. Queue
B. Stack
C. Hash map
D. Linked list only

15 What is the goal of finding the minimum length sorted sub-array?

Finding Minimum Length Sorted Sub-array to Sort an Array Easy
A. Find the largest element
B. Find the shortest section to sort
C. Sort every element twice
D. Remove all duplicate values

16 If an array is already sorted, what is the minimum sub-array length that needs sorting?

Finding Minimum Length Sorted Sub-array to Sort an Array Easy
A.
B.
C.
D.

17 Which order is commonly used when sorting strings lexicographically?

Sorting Strings Easy
A. Dictionary order
B. Reverse input order
C. Length order only
D. Random order

18 Which string comes first in lexicographic order?

Sorting Strings Easy
A. zebra
B. apple
C. carrot
D. banana

19 In ASCII-based sorting, which character generally comes first?

Case-specific sorting of strings Easy
A. Lowercase z
B. Uppercase A
C. Uppercase Z
D. Lowercase a

20 What does case-insensitive sorting do?

Case-specific sorting of strings Easy
A. Removes all spaces
B. Keeps only uppercase letters
C. Ignores letter case
D. Sorts by string length

21 A comparison-based sorting algorithm must sort every possible permutation of distinct elements. What lower bound applies to its worst-case number of comparisons?

Introduction to O(n logn) Sorting Algorithms Medium
A. because each element must be compared with every other element
B.
C.
D.

22 Which algorithm guarantees worst-case time while also sorting an array in place using only auxiliary array storage?

Introduction to O(n logn) Sorting Algorithms Medium
A. Merge sort
B. Heap sort
C. Insertion sort
D. Quick sort

23 A recursive merge sort is called on an array of elements. Assuming splitting continues until sub-arrays have one element, how many merge levels are required?

Iterative & Recursive Merge Sort Medium
A.
B.
C.
D.

24 In bottom-up iterative merge sort, the initial run size is . What sequence of run sizes is processed when sorting an array of elements?

Iterative & Recursive Merge Sort Medium
A.
B.
C. , including a full merge pass for size
D.

25 During the merge step, two records have equal keys, with the left record appearing earlier in the original array. Which comparison preserves merge sort's stability?

Iterative & Recursive Merge Sort Medium
A. Choose the left record only when
B. Alternate between the left and right records whenever their keys are equal
C. Choose the left record when
D. Choose the right record when

26 Lomuto partition is applied to [4, 2, 7, 3, 1, 5], using the last element as the pivot. What array and pivot index result after one partition?

Quick Sort Medium
A. [4, 2, 1, 3, 5, 7], index 3
B. [1, 2, 3, 4, 5, 7], index 4
C. [2, 3, 1, 4, 7, 5], index 3
D. [4, 2, 3, 1, 5, 7], index 4

27 Quick sort always selects the first element as pivot. Which input is most likely to produce its worst-case running time?

Quick Sort Medium
A. An array split into two equal unsorted halves
B. An array already sorted in ascending order
C. An array randomly shuffled without duplicates
D. An array whose first element is always close to the median value

28 An optimized quick sort recursively processes the smaller partition and handles the larger partition iteratively. What is the main benefit of this strategy?

Quick Sort Medium
A. It reduces worst-case running time to
B. It makes quick sort stable while retaining its original partition procedure
C. It makes every partition perfectly balanced
D. It limits auxiliary stack space to

29 Sort [4, 6, 2, 4, 3, 2, 4, 3, 3] by decreasing frequency. If frequencies tie, preserve the order in which values first appeared. What is the result?

Sorting Elements by Frequency Medium
A. [3, 3, 3, 4, 4, 4, 2, 2, 6]
B. [4, 4, 4, 3, 3, 3, 2, 2, 6]
C. [4, 3, 4, 3, 2, 4, 3, 2, 6]
D. [6, 2, 2, 4, 4, 4, 3, 3, 3]

30 Elements are sorted by decreasing frequency, with smaller values first when frequencies tie. What is the sorted form of [5, 2, 5, 3, 2, 4]?

Sorting Elements by Frequency Medium
A. [2, 2, 5, 5, 3, 4]
B. [5, 5, 2, 2, 3, 4]
C. [2, 2, 5, 5, 4, 3]
D. [3, 4, 2, 2, 5, 5]

31 For the array [1, 3, 5, 4, 2, 6, 7], what is the minimum length of a contiguous sub-array that must be sorted to make the entire array sorted?

Finding Minimum Length Sorted Sub-array to Sort an Array Medium
A.
B.
C.
D.

32 What should an algorithm return as the minimum sub-array length when the input array is already sorted in nondecreasing order?

Finding Minimum Length Sorted Sub-array to Sort an Array Medium
A.
B. because no valid contiguous sub-array exists
C.
D.

33 After locating the first inversion from each end, an algorithm finds the minimum and maximum values inside the candidate sub-array. Why may its boundaries need to be expanded?

Finding Minimum Length Sorted Sub-array to Sort an Array Medium
A. The candidate must always contain at least half of the array
B. Values outside may violate order relative to the candidate minimum or maximum
C. The boundaries must reach both array ends to guarantee a globally sorted result
D. Every duplicate value must be included regardless of its position

34 Using case-sensitive ASCII lexicographic order, what is the sorted order of ['Zebra', 'apple', 'Banana', 'apricot']?

Sorting Strings Medium
A. ['Banana', 'Zebra', 'apple', 'apricot']
B. ['Zebra', 'Banana', 'apple', 'apricot']
C. ['apple', 'apricot', 'Banana', 'Zebra']
D. ['Banana', 'apple', 'apricot', 'Zebra']

35 Strings are sorted first by increasing length and then lexicographically when lengths tie. What is the result for ['pear', 'fig', 'apple', 'kiwi', 'plum']?

Sorting Strings Medium
A. ['fig', 'pear', 'kiwi', 'plum', 'apple']
B. ['apple', 'kiwi', 'pear', 'plum', 'fig']
C. ['fig', 'kiwi', 'pear', 'plum', 'apple']
D. ['fig', 'kiwi', 'plum', 'pear', 'apple']

36 Sort lowercase and uppercase letters separately while preserving which positions contain lowercase and uppercase letters. What does defRTSersUXI become?

Case-specific sorting of strings Medium
A. deefrsIRSTUX
B. IRSdeeTfrsUX
C. deeIRSfrsTUX
D. deeIRSfTrsUX

37 A stable case-insensitive sort is applied to ['Bob', 'alice', 'ALICE', 'bob']. What is the result?

Case-specific sorting of strings Medium
A. ['alice', 'ALICE', 'Bob', 'bob']
B. ['Bob', 'bob', 'alice', 'ALICE']
C. ['alice', 'ALICE', 'bob', 'Bob']
D. ['ALICE', 'alice', 'Bob', 'bob']

38 How many distinct value pairs in [1, 5, 3, 4, 2, 2] have an absolute difference of ?

Count Distinct Pairs with Difference of K Medium
A.
B.
C.
D.

39 For [1, 1, 1, 2, 2, 3], how many distinct value pairs have an absolute difference of ?

Count Distinct Pairs with Difference of K Medium
A.
B.
C.
D.

40 A sorted array may contain duplicates. In a two-pointer algorithm that counts distinct pairs with difference , what should happen after a valid pair is found?

Count Distinct Pairs with Difference of K Medium
A. Advance only the right pointer by exactly one position
B. Reset the left pointer to the beginning of the array
C. Count every repeated occurrence before advancing either pointer
D. Advance both pointers past duplicates of their current values

41 Why can no deterministic comparison-based sorting algorithm guarantee substantially fewer than comparisons for every permutation of distinct elements?

Introduction to O(n logn) Sorting Algorithms Hard
A. Its decision tree needs at least leaves, so its height is at least
B. Every element must be compared directly with each of its two sorted neighbors
C. Each comparison places exactly one element into its final sorted position
D. Its recursion tree must be balanced and contain exactly internal nodes for every input

42 Two independently sorted arrays contain and distinct elements. What is the tight worst-case number of comparisons needed to merge them into one sorted array?

Introduction to O(n logn) Sorting Algorithms Hard
A.
B.
C.
D.

43 A bottom-up merge sort processes an array of length using run widths . It invokes the merge procedure only when a right run exists. How many width passes and merge invocations occur?

Iterative & Recursive Merge Sort Hard
A. 4 passes and 13 merges
B. 5 passes and 13 merges
C. 5 passes and 12 merges
D. 4 passes and 12 merges

44 During merge sort, the left and right halves are already sorted. If the next right-half value is smaller than the next left-half value at index , how should an inversion-counting implementation update the count?

Iterative & Recursive Merge Sort Hard
A. Add the number of unmerged elements remaining in the left half
B. Add one because only the two current elements form an inversion
C. Add the complete size of the left half, including elements that were merged earlier
D. Add the number of unmerged elements remaining in the right half

45 A recursive merge sort alternates the roles of source and destination arrays at successive recursion levels. What is the main benefit of this technique when implemented correctly?

Iterative & Recursive Merge Sort Hard
A. It reduces the comparison complexity to
B. It removes the auxiliary array and guarantees space
C. It avoids copying every merged range back into the original array
D. It makes merging stable without checking equal keys

46 Suppose every Quick Sort pivot splits a subarray of size into parts of sizes approximately and . Which asymptotic bounds describe the total running time and the longest recursion path?

Quick Sort Hard
A. time and depth
B. time and depth
C. time and depth
D. time and depth

47 For randomized Quick Sort on distinct elements, where every pivot is chosen uniformly, what is the expected number of key comparisons?

Quick Sort Hard
A.
B.
C.
D.

48 An array contains identical keys. How does randomized Quick Sort behave when using a correct three-way partition into keys less than, equal to, and greater than the pivot?

Quick Sort Hard
A. It finishes in time with logarithmic recursive depth
B. It requires time because every pivot has the same value
C. It repeatedly recurses on the equal segment after scanning the entire segment at each level
D. It finishes in time with constant recursive depth

49 Sort [4, 6, 2, 4, 3, 2, 4, 6, 2] by decreasing frequency, breaking equal-frequency ties by first occurrence in the original array. What is the result?

Sorting Elements by Frequency Hard
A. [3, 6, 6, 4, 4, 4, 2, 2, 2]
B. [2, 2, 2, 4, 4, 4, 6, 6, 3]
C. [4, 4, 4, 2, 2, 2, 3, 6, 6]
D. [4, 4, 4, 2, 2, 2, 6, 6, 3]

50 An array of length has only distinct values. Frequencies are stored in a hash map, distinct values are sorted by (-frequency, value), and each value is then emitted according to its frequency. What is the expected time complexity?

Sorting Elements by Frequency Hard
A.
B.
C.
D.

51 For the array [1, 3, 5, 4, 2, 6, 7], which smallest zero-based inclusive interval must be sorted so that the entire array becomes nondecreasing?

Finding Minimum Length Sorted Sub-array to Sort an Array Hard
A. [2, 4]
B. [2, 5]
C. [1, 5]
D. [1, 4]

52 After finding an initial unsorted interval $[l,r]`, let $m$ and $M$ be its minimum and maximum. Which expansion rule gives the minimum interval for a nondecreasing final array?

Finding Minimum Length Sorted Sub-array to Sort an Array Hard
A. Expand left while and right while
B. Expand both boundaries whenever either neighboring value lies anywhere inside the closed interval , including values equal to its endpoints
C. Expand left while and right while
D. Expand left while and right while

53 A function must return the length of the smallest subarray whose sorting makes the full array nondecreasing. What should it return for [1, 2, 2, 3, 5]?

Finding Minimum Length Sorted Sub-array to Sort an Array Hard
A. 2
B. 1
C. 0
D. 5

54 A comparison sort orders strings, each of length at most , using ordinary lexicographic comparison without caching longest common prefixes. What is its worst-case character-comparison complexity?

Sorting Strings Hard
A.
B.
C.
D.

55 Using code-point lexicographic order, where uppercase A precedes lowercase a and a proper prefix precedes the longer string, how are ["a", "aa", "", "ab", "A"] sorted?

Sorting Strings Hard
A. ["", "A", "aa", "ab", "a"]
B. ["A", "", "a", "aa", "ab"]
C. ["", "a", "A", "aa", "ab"]
D. ["", "A", "a", "aa", "ab"]

56 Uppercase letters must be sorted among the original uppercase positions, and lowercase letters among the original lowercase positions. Applying this rule to bAcDaeC produces which string?

Case-specific sorting of strings Hard
A. AabCceD
B. aAbcCeD
C. aABCcde
D. aAbCceD

57 Which set of conditions is sufficient to verify an output of case-specific string sorting?

Case-specific sorting of strings Hard
A. Uppercase letters precede lowercase letters, both groups are sorted, and duplicate letters are removed
B. The case-position mask is unchanged, both case projections are sorted, and the character multiset is preserved
C. The full output is globally sorted, its length is unchanged, and its first character preserves its original case
D. Each character remains at its original index unless another character has the same alphabetic rank under case-insensitive comparison

58 For [1, 1, 1, 2, 2, 3, 4, 4], how many distinct unordered value pairs satisfy an absolute difference of ?

Count Distinct Pairs with Difference of K Hard
A. 7
B. 3
C. 5
D. 10

59 For [1, 1, 3, 3, 5, 5, 7], how many distinct unordered value pairs have absolute difference ?

Count Distinct Pairs with Difference of K Hard
A. 6
B. 12
C. 8
D. 3

60 A sorted, deduplicated array is scanned with indices to count pairs satisfying for . Which pointer-update rule is correct?

Count Distinct Pairs with Difference of K Hard
A. Advance if the difference is too small, advance if too large, and advance both after a match
B. Advance both pointers whenever the difference is not , but advance only after finding a matching pair
C. Advance if the difference is too small, advance if too large, and advance both after a match
D. Reset to zero after every match and continue moving so that all duplicate index combinations are counted separately