Bubble Sort MCQ Quiz

Reviewed by Godwin Iheuwa
Godwin Iheuwa, MS, Computer Science |
Computer Expert
Review Board Member
Godwin is a proficient Database Administrator currently employed at MTN Nigeria. He holds as MS in Computer Science from the University of Bedfordshire, where he specialized in Agile Methodologies and Database Administration. He also earned a Bachelor's degree in Computer Science from the University of Port Harcourt. With expertise in SQL Server Integration Services (SSIS) and SQL Server Management Studio, Godwin's knowledge and experience enhance the authority of our quizzes, ensuring accuracy and relevance in the realm of computer science.
, MS, Computer Science
Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By RosyU
R
RosyU
Community Contributor
Quizzes Created: 6 | Total Attempts: 41,500
Questions: 10 | Attempts: 13,901

SettingsSettingsSettings
Bubble Sort MCQ Quiz - Quiz

Here is an amazing Bubble sort Quiz. You can also call it a selection sort quiz. This Quiz is to check your knowledge of the Bubble sort algorithm or selection sort algorithm. If you think you understand enough about the Bubble sort algorithm and you can pass this test with a good score, then try your luck here. If you manage to get 80 or above in this selection sort quiz, that would be excellent—best of luck with your test here.


Bubble Sort Questions and Answers

  • 1. 

    What are the correct intermediate steps of the following data set when it is being sorted with the bubble sort? 15,20,10,18

    • A.

      15,10,20,18 -- 15,10,18,20 -- 10,15,18,20

    • B.

      10, 20,15,18 -- 10,15,20,18 -- 10,15,18,20

    • C.

      15,20,10,18 -- 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20

    • D.

      15,18,10,20 -- 10,18,15,20 -- 10,15,18,20 -- 10,15,18,20

    Correct Answer
    C. 15,20,10,18 -- 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20
    Explanation
    Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The algorithm gets its name because smaller elements "bubble" to the top of the list with each iteration.
    Let's walk through the steps:
    15, 20, 10, 18: In the first pass, we compare 15 and 20 (no swap), then 20 and 10 (swap to get 10, 20, 15, 18), and finally, 20 and 18 (no swap). The largest element, 20, bubbles up to the end.
    10, 15, 20, 18: In the second pass, we compare 10 and 15 (no swap), then 15 and 20 (no swap), and finally 20 and 18 (swap to get 10, 15, 18, 20). Now, the second largest element, 15, is in its correct position.
    10, 15, 18, 20: In the third pass, no swaps are needed as all elements are already in order.
    So, the correct intermediate steps are:
    15, 20, 10, 18
    15, 10, 20, 18
    10, 15, 20, 18
    10, 15, 18, 20
    This matches option C.

    Rate this question:

  • 2. 

    In a bubble sort structure, there is/are?

    • A.

      A single for loop

    • B.

      Three for loops, all separate

    • C.

      A while loop

    • D.

      Two for loops, one nested in the other

    Correct Answer
    D. Two for loops, one nested in the other
    Explanation
    The correct answer is two for loops, one nested in the other. In a bubble sort structure, the outer loop iterates through the entire array, while the inner loop compares adjacent elements and swaps them if they are in the wrong order. This process is repeated until the array is sorted.

    Rate this question:

  • 3. 

    What is the maximum number of comparisons if there are 5 elements in array x?

    • A.

      10

    • B.

      2

    • C.

      5

    • D.

      25

    Correct Answer
    A. 10
    Explanation
    If there are 5 elements in array x, the maximum number of comparisons can be calculated using the formula n*(n-1)/2, where n is the number of elements in the array. In this case, n=5, so the maximum number of comparisons is 5*(5-1)/2 = 10.

    Rate this question:

  • 4. 

    What is the maximum number of comparisons that can take place when a bubble sort is implemented? Assume there are n elements in the array?

    • A.

      (1/2)(n-1)

    • B.

      (1/2)n(n-1)

    • C.

      (1/4)n(n-1)

    • D.

      None of the above

    Correct Answer
    B. (1/2)n(n-1)
    Explanation
    The maximum number of comparisons that can take place when a bubble sort is implemented is (1/2)n(n-1). In a bubble sort, each element is compared with its adjacent element and swapped if necessary. The number of comparisons decreases by 1 with each pass through the array, as the largest element "bubbles" to its correct position. Therefore, the total number of comparisons can be calculated by summing the numbers from 1 to n-1, which is equal to (1/2)n(n-1).

    Rate this question:

  • 5. 

    What are the worst case and best case time complexity of bubble sort consequently?

    • A.

      O(n), O(n2)

    • B.

      O(n2), O(n3)

    • C.

      O(n), O(n3)

    • D.

      None of the above

    Correct Answer
    A. O(n), O(n2)
    Explanation
    Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. In the best-case scenario, when the list is already sorted, the algorithm only needs to make one pass through the list to confirm that it is sorted, resulting in a time complexity of O(n). However, in the worst-case scenario, when the list is in reverse order, the algorithm needs to make n-1 passes through the list and perform comparisons and swaps at each step, resulting in a time complexity of O(n^2).

    Rate this question:

  • 6. 

    Which one of the following is the first step in a selection sort algorithm?

    • A.

      The minimum value in the list is found.

    • B.

      The maximum value in the list is found.

    • C.

      Adjacent elements are swapped.

    Correct Answer
    A. The minimum value in the list is found.
    Explanation
    In a selection sort algorithm, the first step is to find the minimum value in the list. This is done by comparing each element with the current minimum value and updating the minimum value if a smaller element is found. Once the minimum value is found, it is swapped with the first element in the list. This process is repeated for the remaining elements in the list, finding the minimum value and swapping it with the next element. This continues until the list is sorted in ascending order.

    Rate this question:

  • 7. 

    How many passes/scans will go through a list of 10 elements?

    • A.

      3

    • B.

      5

    • C.

      7

    • D.

      9

    Correct Answer
    D. 9
    Explanation
    In order to go through a list of 10 elements, we need to iterate over each element once. This requires a single pass or scan. However, the answer provided is 9, which is incorrect. It is possible that the question is incomplete or there is missing information that would justify the answer of 9. Without further context, it is not possible to provide a clear explanation for this answer.

    Rate this question:

  • 8. 

    Bubble sorting got its name from a Bubble gum company that used it for the first time.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The given statement is false. Bubble sorting is a simple sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. It is called "bubble sorting" because during each iteration, the largest unsorted element "bubbles" up to its correct position in the sorted portion of the array. The statement about a Bubble gum company using it for the first time is not true.

    Rate this question:

  • 9. 

    How many passes (or "scans") will there be through a list being sorted using a selection sort?

    • A.

      Array_size*2

    • B.

      Array_size+1

    • C.

      Array_size-1

    • D.

      None of the above

    Correct Answer
    C. Array_size-1
    Explanation
    The number of passes or scans through a list being sorted using selection sort is equal to the size of the array minus one. In each pass, the algorithm selects the smallest element from the unsorted portion of the list and swaps it with the first unsorted element. This process is repeated until the entire list is sorted. Since the last element does not need to be compared with any other elements, there is no need for a final pass. Therefore, the number of passes is equal to the size of the array minus one.

    Rate this question:

  • 10. 

    When using Bubble sort, what number of swappings are required to sort the numbers 8,22,7,931,5,13 in ascending order?

    • A.

      5

    • B.

      10

    • C.

      12

    • D.

      14

    Correct Answer
    C. 12
    Explanation
    Here’s how Bubble Sort would sort the list:
    First pass: 8,7,22,5,13,931 (3 swaps: 22 and 7, 22 and 5, 22 and 13)
    Second pass: 7,8,5,13,22,931 (2 swaps: 8 and 5, 8 and 13)
    Third pass: 7,5,8,13,22,931 (1 swap: 7 and 5)
    Fourth pass: 5,7,8,13,22,931 (0 swaps)
    Fifth pass: 5,7,8,13,22,931 (0 swaps)
    So, a total of 3 + 2 + 1 + 0 + 0 = 6 passes and 12 swaps are required to sort the list in ascending order. Please note that understanding the principles of algorithms, such as bubble sort, is crucial for effective software development. Always ensure to follow best coding practices when working with algorithms.

    Rate this question:

Godwin Iheuwa |MS, Computer Science |
Computer Expert
Godwin is a proficient Database Administrator currently employed at MTN Nigeria. He holds as MS in Computer Science from the University of Bedfordshire, where he specialized in Agile Methodologies and Database Administration. He also earned a Bachelor's degree in Computer Science from the University of Port Harcourt. With expertise in SQL Server Integration Services (SSIS) and SQL Server Management Studio, Godwin's knowledge and experience enhance the authority of our quizzes, ensuring accuracy and relevance in the realm of computer science.

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 14, 2024
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Godwin Iheuwa
  • Dec 25, 2011
    Quiz Created by
    RosyU
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.