GATE DA 2026 Set 1 — Question 49
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MSQ+2 / -0MediumBubble SortSearching & SortingProgramming, Data Structures & AlgorithmsInsertion Sort
Programming, Data Structures & Algorithms → Searching & Sorting → Bubble Sort
Last updated
Question
Consider the problem of sorting the given array in ascending order:Consider two sorting algorithms Bubble Sort (BS) and Insertion Sort (IS).Let be the total number of comparisons done by BS on the elements of P and be the total number of comparisons done by IS on the elements of P.Which of the following options is/are correct?
Correct answer
(B) N1 N2; (C) IS on P will perform only one swap; (D) Both BS and IS on P will make at least one unnecessary comparison (i.e., comparing elements that are already in correct order)
Solution
For the array ():Bubble Sort (BS):
Standard Bubble Sort performs comparisons for to and to .
Standard Bubble Sort performs comparisons for to and to .
- Pass 1 (): (1,2), (2,3), (3,5), (5,4). 4 comparisons. Swap (5,4). Array becomes .
- Pass 2 (): (1,2), (2,3), (3,4). 3 comparisons. No swaps.
- Pass 3 (): (1,2), (2,3). 2 comparisons.
- Pass 4 (): (1,2). 1 comparison.
- Element 2: Compare with 1. (1 comparison). No swap.
- Element 3: Compare with 2. (1 comparison). No swap.
- Element 5: Compare with 3. (1 comparison). No swap.
- Element 4: Compare with 5 (4 < 5, swap/shift). Compare with 3 (4 > 3, stop). (2 comparisons).
- (A) . False (N2 is 5).
- (B) (). True.
- (C) IS performs only one swap (swapping 5 and 4). True.
- (D) BS compares sorted elements (e.g., 1 and 2) multiple times. IS compares sorted elements (e.g., 2 and 1) to verify position. Both make comparisons on elements already in order. True.
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE DA question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Searching & Sorting
2026 Set 1 Q15Consider that the quick sort algorithm is used to sort an array of distinct randomly ordered…2026 Set 1 Q16Consider the given Python program. [code] Which of the following is the correct output of this…2026 Set 1 Q25You are given the following Pre-order and In-order traversals of a Binary Tree T with nodes E, F,…2026 Set 1 Q31Let A be a sorted array containing 1000 distinct integers. You perform a recursive binary search on…2026 Set 1 Q39A recursive function in Python is given. [code] Now, consider the following function call:…