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.