Whenever you're ready, walk me through how you'd approach this.
Explain how a sorting algorithm works and discuss its time complexity in common scenarios.
Choose one sorting algorithm and describe its steps, then compare its best-case, average-case, and worst-case time complexity. Also discuss space complexity, stability, and when you would choose it over another sorting algorithm. Keep the explanation language-agnostic, but you may use pseudocode or a short code example.