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.