def quicksort_lc(nums):
    """Quick sort algorithm by recursion with list comprehension.

    Procedure:
      - Pick a pivot which ideally is a median pf the list.
      - Arrange half elements which are smaller than pivot to left,
        and the other half ones that are bigger than pivot to right.
      - Then to each half, recursively apply quick sort.

    Time complexity: O(n*logn).
    Space complexity: O(n).
    """
    # Base case.
    if len(nums) <= 1:
        return nums

    # Use middle num as pivot to collect small, middle & large numbers.
    pivot = nums[len(nums) // 2]
    smalls = [x for x in nums if x < pivot]
    middles = [x for x in nums if x == pivot]
    larges = [x for x in nums if x > pivot]

    # Concat small, middle & large numbers.
    return quicksort_lc(smalls) + middles + quicksort_lc(larges)