CodeTestValidate

No installations needed! Write Python directly in your browser and get instant feedback with our smart validation system.

Challenge # 2

Bubble Sort and Insertion Sort

Objective

Implement two classic sorting algorithms: Bubble Sort and Insertion Sort.

Instructions

  • You are given a list of integers named nums.

  • Write two separate functions: bubble_sort(nums) and insertion_sort(nums).

  • Each function should return a new sorted list in ascending order.

  • Do not use built-in sorting functions like sorted() or .sort().

  • Use the respective algorithm’s logic to sort the list.

Constraints:
Do not use input(). • Do not use built-in `sorted()` or `.sort()` methods.
Exemple IO

Input: nums = [5, 2, 9, 1, 5, 6]

Output: Bubble Sort: [1, 2, 5, 5, 6, 9] Insertion Sort: [1, 2, 5, 5, 6, 9]

Input: nums = [3, 0, -2, 10, 7]

Output: Bubble Sort: [-2, 0, 3, 7, 10] Insertion Sort: [-2, 0, 3, 7, 10]

Try It Online!

Output:

Validate Your Results

Get your code reviewed and validated to understand what you did right and where you can improve.

Previous challengeBasic CalculatorNext challengeBinary Search
Loading...