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 করুন এবং space দিয়ে আলাদা করে 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.