Quicksort is a divide and conquer sorting algorithm that works by partitioning an array around a pivot value and recursively sorting the subarrays. In the best case when the array is partitioned evenly, quicksort runs in O(n log n) time as the array is cut in half at each recursive call. However, in the worst case when the array is already sorted, each partition only cuts off one element, resulting in O(n^2) time as the recursion reaches a depth of n. Choosing a better pivot value can improve quicksort's performance on poorly sorted arrays.