Theory
Sorting means arranging elements according to a chosen order, such as ascending or descending. Common sorting algorithms include Bubble Sort, Selection Sort, Insertion Sort, Merge Sort and Quick Sort. Different algorithms have different performance characteristics.
Example
const numbers = [5, 2, 8, 1];
numbers.sort((a, b) => a - b);
console.log(numbers);
Expected Output
[1, 2, 5, 8]
Practice
Implement Bubble Sort without using the built-in sort method.
Interview Questions
- What is sorting?
- Name some sorting algorithms.
- What is Bubble Sort?
- Which sorting algorithms are commonly used in practice?