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.