Lesson 12 of 23

Searching आणि Bubble Sort

11 min 30 XP

Bubble sort शेजारच्या घटकांची तुलना करतो आणि क्रम चुकला असेल तर swap करतो; प्रत्येक pass सर्वात मोठी value शेवटी नेतो. Time complexity: O(n²).

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Sorted array वर binary search मधल्या घटकाशी तुलना करून प्रत्येक वेळी अर्धा भाग सोडतो: O(log n), म्हणजे दहा लाख घटकांनाही सुमारे 20 पायऱ्या!

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Challenge

+30 XP

n आणि n संख्या वाचा, bubble sort ने त्या उतरत्या क्रमाने sort करा आणि spaces ने वेगळ्या करून print करा. Input: 5 3 8 1 9 4 Output: 9 8 4 3 1

Output Loading C (first time takes a few seconds)
Press Run to see the result here.