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.