Question:
What is the total number of swappings performed by Bubble Sort on an array of \(n\) elements that is already sorted in ascending order?
आरोही क्रम में पहले से सॉर्ट किए गए \(n\) तत्वों के ऐरे पर बबल सॉर्ट द्वारा किए गए कुल स्वैप (Swappings) की संख्या क्या होगी?
Options:
- 0
- \(n\)
- \(n(n-1)/2\)
- \(n – 1\)
- 0
- \(n\)
- \(n(n-1)/2\)
- \(n – 1\)
Correct Answer: a)
Explanation:
In an already sorted array, no adjacent elements are out of order, so **0 swappings** are executed (with a swapped flag, it terminates in \(O(n)\) time) (Option a).
पहले से सॉर्ट किए गए ऐरे में कोई भी अवयव गलत क्रम में नहीं होता, इसलिए स्वैप की संख्या **0** होती है (विकल्प a)।