Sorting and Searching Essentials: Fundamentals Quiz Quiz

Assess your understanding of basic sorting algorithms, custom sort keys, and common binary search scenarios. This quiz is designed to reinforce foundational knowledge in ordering data and efficient search methods.

  1. Identifying Built-in Sorting Orders

    Given the list [4, 1, 3, 2], what will be the result after applying a standard ascending sort?

    1. [1, 2, 3, 4]
    2. [4, 3, 2, 1]
    3. [4, 2, 1, 3]
    4. [1, 3, 2, 4]
    5. [2, 1, 3, 4]
  2. Purpose of a Custom Sort Key

    Which statement best describes the purpose of providing a custom sort key when sorting a collection?

    1. It reverses the sorting order by default.
    2. It increases sorting performance always.
    3. It prevents duplicate elements from being sorted.
    4. It determines how elements are compared during sorting.
    5. It changes the data type of each element.
  3. Case-insensitive Sorting

    When sorting the strings ['apple', 'Banana', 'cherry'] in a case-insensitive way, which function can be used as a custom key?

    1. str.search
    2. str.uppercase
    3. str.append
    4. str.concat
    5. str.lower
  4. Binary Search Prerequisite

    Binary search requires which important property to work correctly on a list?

    1. The list must contain only numbers.
    2. The list size must be even.
    3. The list must start with zero.
    4. The list must be sorted.
    5. The list must have only unique elements.
  5. Binary Search Midpoint Edge Case

    In binary search, what is a common mistake when calculating the middle index for very large lists?

    1. Sorting the list before searching.
    2. Returning from the function too early.
    3. Including duplicate values in search.
    4. Overflow when adding low and high indices.
    5. Ignoring negative numbers in the list.
  6. Descending Order Sorting

    To sort [10, 2, 7, 4] in descending order, which parameter should be set to True in many sorting functions?

    1. order_by
    2. invert_sort
    3. reverse
    4. invert
    5. descend
  7. Custom Sort Key for Sorting by Length

    If you want to sort a list of words by the number of characters, which built-in function is most appropriate as the key?

    1. len
    2. max
    3. sum
    4. num
    5. ord
  8. Non-Existent Element in Binary Search

    What is the expected result when performing binary search for 5 in the sorted list [1, 2, 4, 6, 8]?

    1. Duplicate found
    2. Middle element
    3. First element
    4. Not found
    5. List will be resorted
  9. Stability in Sorting Algorithms

    If a sorting algorithm preserves the order of equal elements, what property is this called?

    1. Simplicity
    2. Flexibility
    3. Stability
    4. Reversibility
    5. Scalability
  10. Lowest Index Binary Search

    When searching for the value 3 in [1, 2, 3, 3, 3, 4], using binary search, what must be added to return the index of the first occurrence?

    1. Return the highest index found
    2. Use linear search after binary search
    3. Double the size of the list
    4. Modify binary search to continue left after finding 3
    5. Sort the list after every comparison