0% found this document useful (0 votes)
12 views4 pages

20 Bubble Sort Examples Explained

The document presents 20 Bubble Sort questions with examples for both ascending and descending order sorting. Each question includes an example input array and the corresponding expected output after applying Bubble Sort. The examples cover various scenarios, including sorting arrays with duplicates, negative numbers, and custom sorting conditions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

20 Bubble Sort Examples Explained

The document presents 20 Bubble Sort questions with examples for both ascending and descending order sorting. Each question includes an example input array and the corresponding expected output after applying Bubble Sort. The examples cover various scenarios, including sorting arrays with duplicates, negative numbers, and custom sorting conditions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

20 Bubble Sort Questions with Examples

(Ascending & Descending)

Created on: 2025-10-26 05:55 UTC

1. 1. Basic Bubble Sort (Ascending)


Sort the given array in ascending order using Bubble Sort.

Example Input: [5, 3, 8, 4, 2]

Example Output: [2, 3, 4, 5, 8]

2. 2. Sort Already Sorted Array


Apply Bubble Sort on an already sorted array.

Example Input: [1, 2, 3, 4, 5]

Example Output: [1, 2, 3, 4, 5]

3. 3. Sort Reverse Array


Sort a reverse-sorted array using Bubble Sort.

Example Input: [9, 8, 7, 6, 5]

Example Output: [5, 6, 7, 8, 9]

4. 4. Sort Array with Duplicates


Sort an array that contains duplicate values.

Example Input: [4, 2, 4, 3, 2]

Example Output: [2, 2, 3, 4, 4]

5. 5. Sort Negative Numbers


Sort an array containing negative numbers using Bubble Sort.

Example Input: [3, -1, -4, 2, 0]

Example Output: [-4, -1, 0, 2, 3]

6. 6. Sort Floating Numbers


Sort an array of floating-point numbers.

Example Input: [2.3, 1.1, 4.5, 3.2]

Example Output: [1.1, 2.3, 3.2, 4.5]

7. 7. Sort Array of Characters


Sort characters alphabetically using Bubble Sort.

Example Input: ['d', 'a', 'c', 'b']

Example Output: ['a', 'b', 'c', 'd']

8. 8. Sort Odd Numbers Only


Sort only odd numbers while keeping even numbers in place (custom use of Bubble Sort).

Example Input: [5, 2, 3, 8, 1]

Example Output: [1, 2, 3, 8, 5]

9. 9. Sort Small Array


Use Bubble Sort on a small array of 3 elements.

Example Input: [9, 3, 1]

Example Output: [1, 3, 9]

10. 10. Sort Large Array


Use Bubble Sort on a larger array (basic performance test).

Example Input: [9, 4, 7, 1, 5, 3, 8, 2, 6]

Example Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

11. 11. Basic Bubble Sort (Descending)


Sort the given array in descending order using Bubble Sort.

Example Input: [5, 3, 8, 4, 2]

Example Output: [8, 5, 4, 3, 2]

12. 12. Sort Already Descending Array


Apply Bubble Sort on an already descending array.
Example Input: [9, 7, 5, 3, 1]

Example Output: [9, 7, 5, 3, 1]

13. 13. Sort Ascending to Descending


Convert an ascending array into descending order using Bubble Sort.

Example Input: [1, 2, 3, 4, 5]

Example Output: [5, 4, 3, 2, 1]

14. 14. Sort with Duplicate Values


Sort an array with duplicate numbers in descending order.

Example Input: [4, 2, 4, 3, 2]

Example Output: [4, 4, 3, 2, 2]

15. 15. Sort with Negative Numbers


Sort an array with negative numbers in descending order.

Example Input: [3, -1, -4, 2, 0]

Example Output: [3, 2, 0, -1, -4]

16. 16. Sort Floating Numbers Descending


Sort floating-point numbers in descending order using Bubble Sort.

Example Input: [2.3, 1.1, 4.5, 3.2]

Example Output: [4.5, 3.2, 2.3, 1.1]

17. 17. Sort Characters Descending


Sort characters in reverse alphabetical order.

Example Input: ['a', 'd', 'b', 'c']

Example Output: ['d', 'c', 'b', 'a']

18. 18. Sort Even Numbers Only


Sort only even numbers in descending order (custom logic).

Example Input: [5, 2, 3, 8, 4]


Example Output: [5, 8, 3, 4, 2]

19. 19. Sort Random Array Descending


Sort a random array in descending order using Bubble Sort.

Example Input: [6, 1, 9, 3, 7]

Example Output: [9, 7, 6, 3, 1]

20. 20. Sort User Input Array


Take array input from the user and sort it in descending order using Bubble Sort.

Example Input: [3, 5, 1, 9, 2]

Example Output: [9, 5, 3, 2, 1]

You might also like